要添加并训练自己的类别,最关键的还是 源码文件夹下/tensorflow/tensorflow/examples/image_retraining
的retain.py文件,其实文件一开始已经写的很清楚了,我怕忘了,在此记录一下,请看retain.py的这部分
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
以上告诉你自己数据的文件结构
这部分
python tensorflow/examples/image_retraining/retrain.py \
--image_dir ~/flower_photos
```
You can replace the image_dir argument with any folder containing subfolders of
images. The label for each image is taken from the name of the subfolder it's
in.
This produces a new model file that can be loaded and run by any TensorFlow
program, for example the label_image sample code.
By default this script will use the high accuracy, but comparatively large and
slow Inception v3 model architecture. It's recommended that you start with this
to validate that you have gathered good training data, but if you want to deploy
on resource-limited platforms, you can try the `--architecture` flag with a
Mobilenet model. For example:
```bash
python tensorflow/examples/image_retraining/retrain.py \
--image_dir ~/flower_photos --architecture mobilenet_1.0_224
There are 32 different Mobilenet models to choose from, with a variety of file
size and latency options. The first number can be '1.0', '0.75', '0.50', or
'0.25' to control the size, and the second controls the input image size, either
'224', '192', '160', or '128', with smaller sizes running faster. See
https://research.googleblog.com/2017/06/mobilenets-open-source-models-for.html
for more information on Mobilenet.
这部分告诉你:
1.把图像数据准备好后的运行指令,其中--image_dir 可以是相对路径也可以是绝对路径,只要对就行,不然报错找不到图像
2.--architecture 这个参数是你要训练的模型类型,比如例子是在移动Mobilenet_1.0_224,具体有多少种类型可以看函数create_model_info,里面有两种现成模型,一种是inception_v3 还有一种是用于手机移动端的mobilenet_,这个类型下面又有很多不同组合,具体自己看说明
最后多一嘴,在代码的第151左右有一句extensions = ['jpg', 'jpeg', 'JPG', 'JPEG']告诉你自己的图片格式要求其他格式会报错,当然你添加一下就可以,但不知道结果会不会是想的那样