tensorflow 迁移学习(在已有类别的模型上添加自己的类别)

本文介绍如何使用TensorFlow的retrain.py脚本定制图像分类模型。通过准备图像数据集并运行特定命令,用户可以训练自己的模型。文章还介绍了如何选择不同的模型架构,如Inception v3或MobileNet系列。
摘要由CSDN通过智能技术生成

要添加并训练自己的类别,最关键的还是 源码文件夹下/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']告诉你自己的图片格式要求其他格式会报错,当然你添加一下就可以,但不知道结果会不会是想的那样

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

如雾如电

随缘

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值