GithubHelp home page GithubHelp logo

huixxi / image-classification-using-flowers-dataset Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 34.71 MB

Python 2.46% Jupyter Notebook 97.54%
pre-trained transfer-learning data-augmentation image-classification tfrecords-files tensorflow

image-classification-using-flowers-dataset's Introduction

Image-Classification-using-Flowers-dataset Competition

In “Panorama AI Competition”

这是本人作为小白第一次参加类似的竞赛,总结的这近一个月的时间内踩过的坑,走过的弯路和积累的一些有用的Tricks,分享给和我一样的新手小白们。 【所有参考的Blogs, Tutorials等都给出了明确的出处,有部分资料需要翻墙访问】

What is TFRecords File

在此次竞赛中,训练的图像数据集相对较小,共3500(350x10)张灰度图像(Grayscale),包含5类花朵图片(1-玫瑰(rose), 2-向日葵(sunflower), 3-雏菊(daisy), 4-蒲公英(dandelion), 5-郁金香(tulip)),以*.tfrecord(s)类型文件存储。我是第一次接触这种类型的数据格式,所以也花了很长 时间去理解学习,简单地说:tfrecord file: images which are numpy arrays and labels which are a list of strings,是一种将*.jpeg 或 *.png 等类型图像解码后再储存成tfrecord文件,所以体积会比较大(比如:我在Google Image上面额外找的794M用于扩充训练集的5类花朵图片, 转成.tfrecords文件有3.36G大小 Horrible....)。
这里推荐两篇Blogs供大家参考:
1. Why Every Tensorflow Developer Should Know About Tfrecord
2. Tensorflow Records? What they are and how to use them.

Read from a TFRecords file in Tensorflow

拿到tfrecords类型的数据集之后,第一件事就是先把图片从里面读出来,看看图片是长什么样的,因为是很菜的小白,所以也为此头疼了好久,借鉴了一些非常优秀的教程,
这里是我本人的Notebook代码:
Source Code: Read from TFRecords files and Plot
参考的教程链接:
Youtube Video Tutorial:Tensorflow tutorial_TFRecord tutorial_02
上述视频教程中代码的GitHub地址

Write into a TFRecords file

本人在进行数据集扩充进行数据增强的部分时,需要将自己在网上爬下来的图片转换成tfrecords文件,以便读入自己的模型用于模型的预训练,就顺便学习了一下该如何制作tfrecords文件,本该是后面的内容,就放在tfrecords文件这一块讲了。这里以一个例子进行说明:How to create a deep learning dataset using Google Images,同时这也是一篇非常棒的tutorial。
首先按照教程的操作,也可以直接看我本人整理好的Notebook代码,将Google Image上的相关图片Download到本地。
接下来准备将下载好的全部图片进行标记并转化成tfrecords文件:
本人的Notebook代码:
Source Code: Write_into_TFRecords_files
参考的教程链接(Vely Good!):
How to write into and read from a TFRecords file in TensorFlow

Neural network architecture and Models

终于到神经网络模型的部分了。因为做计算机视觉图像相关,而且又是图像分类这种很基础的方向,卷积神经网络-CNN一定是首选;对于如此小的数据集来说,要想达到一个不错的分类准确率,自然也避不开使用Pre-Trained Models和Transfer Learning。从2012年以来涌现的那么多神经网络模型,如Xception, VGG16, VGG19, ResNet50, InceptionV3, InceptionResNetV2, MobileNet等,我们该如何进行选择。这篇Tutorial:Using Keras Pre-trained Deep Learning models for your own dataset给了我很大的启发。最终我在本次竞赛中使用的是MobileNets,因为和其他模型比起来,它的参数真的是太少了,并且也十分强大。
对于如何使用Pre_trained Models,我参考了如下教程(Still Vely Good!):
1.MobileNet image Classification with Keras
2.Build image classifier using transfer learning - Fine-tuning MobileNet with Keras 1
3.Train image classifier using transfer learning - Fine-tuning MobileNet with Keras 2
4.Sign language image classification - Fine-tuning MobileNet with Keras 3

由于这些预训练模型通常都是用RGB 3-channel 图片进行训练的,为此我对Grayscale训练数据集做了一些预处理工作,包括图片剪裁并将其转成3-channel的“Grayscale”图片(the trick: convert 1-channel grayscale to 3-channel grayscale is included in the final part)

Train and Test

模型一开始是用CPU训练的,产能问题一度使我想要放弃,最后还是迁到了自己电脑上的GTX 950M,真香!
最终的模型:final_model.h5也是基于预训练模型的框架:flowers_5.h5,对全部参数进行重新训练,所以也就没有用到太多迁移学习的地方,但是用自己找的图片数据进行了预训练pre_train_model.h5

Train Code
Test Code

参考Blogs:
1.Data Augmentation Techniques in CNN using Tensorflow

Other Tricks(Including how to denoise grayscale image)

其他的一些Tricks整理在这个NoteBook文件

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.