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

要添加并训练自己的类别,最关键的还是 源码文件夹下/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

<br><br>
You can replace the image_dir argument with any folder containing subfolders of<br>
images. The label for each image is taken from the name of the subfolder it's<br>
in.<br><br>
This produces a new model file that can be loaded and run by any TensorFlow<br>
program, for example the label_image sample code.<br><br>
By default this script will use the high accuracy, but comparatively large and<br>
slow Inception v3 model architecture. It's recommended that you start with this<br>
to validate that you have gathered good training data, but if you want to deploy<br>
on resource-limited platforms, you can try the `--architecture` flag with a<br>
Mobilenet model. For example:<br><br>
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’]告诉你自己的图片格式要求其他格式会报错,当然你添加一下就可以,但不知道结果会不会是想的那样

TensorFlow C3D是用于视频分析的深度学习模型,可以用于识别和分类视频中的动作和事件。迁移学习是指利用一个已经训练好的模型的知识,来加速另一个相关任务的训练过程。在使用TensorFlow C3D进行迁移学习时,可以通过调整预训练模型的参数来适应新的视频分类任务。 首先,需要准备好一个大规模的视频数据集,并对其进行标注和预处理。接下来,可以选择一个已经训练好的C3D模型作为基础模型,通常是在大规模的视频数据集上进行训练的模型。然后,可以利用迁移学习的方法,将基础模型的参数解冻,并在新的视频数据集上进行微调。在微调的过程中,可以根据新数据集的特点进行参数调整和优化,以达到更好的分类效果。 除了微调模型参数外,还可以根据新任务的需要,对模型的架构进行适当调整和改进。比如,可以添加一些额外的全连接层或者调整原有的卷积层结构,以适应新任务的要求。在微调和调整模型架构的过程中,需要使用新的视频数据集进行训练和验证,以评估模型的性能和效果。 通过以上步骤,就可以使用TensorFlow C3D进行迁移学习,快速搭建适用于新视频分类任务的深度学习模型迁移学习能够充分利用已有模型的知识和参数,减少新任务的训练时间和数据需求,提高模型的泛化能力和分类准确度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值