【Tensorflow】基于Inception-v3模型的图像分类器

1. inception-v3 简介

The Inception v3 model is a deep convolutional neural network, which has been pre-trained for the ImageNet Large Visual Recognition Challenge using data from 2012, and it can differentiate between 1,000 different classes, like “cat”, “dishwasher” or “plane”.

The TensorFlow team already prepared a tutorial on how to execute the image classification on your machine. Nevertheless, I’ll show you as well.

2. 官方分类模型使用

下载Tensorflow/models,用tensorflow提供的classify_image进行图像分类:

git clone https://github.com/tensorflow/models.git
cd models/tutorials/image/imagenet
python classify_image.py

执行 python classify_image.py结果如下:

【Tensorflow】基于Inception-v3模型的图像分类器_第1张图片

classify_image.py会首先下载分类器模型:
DATA_URL = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
下载后会放到本地/tmp/imagenet/路径下:

【Tensorflow】基于Inception-v3模型的图像分类器_第2张图片

3. 训练自己的模型

  • 下载代码:
git clone https://github.com/koflerm/tensorflow-image-classifier.git

代码目录:

【Tensorflow】基于Inception-v3模型的图像分类器_第3张图片
  • 到当前目录创建两个文件夹:tf_files 和 training_dataset:
【Tensorflow】基于Inception-v3模型的图像分类器_第4张图片
  • 把图片素材放到training_dataset目录下,图片素材格式如下:
Here's an example, which assumes you have a folder containing class-named 
subfolders, each full of images for each label. The example folder flower_photos
should have a structure like this: 
~/flower_photos/daisy/photo1.jpg
~/flower_photos/daisy/photo2.jpg
~/flower_photos/rose/anotherphoto77.jpg
~/flower_photos/sunflower/somepicture.jpg

例如,我的素材格式如下:

【Tensorflow】基于Inception-v3模型的图像分类器_第5张图片
  • 训练
    直接调用./train.sh开始训练

  • 执行识别命令

python classify.py [image path]

结果如下:

你可能感兴趣的:(【Tensorflow】基于Inception-v3模型的图像分类器)