1 微调的概念
以常见的VGG16作为例子,我们采用VGG16在ImageNet上已经训练好的网络参数作为初始值,并只根据需要来重新训练所有参数或是部分参数。而微调主要有以下几种情况:
1.只训练最后一个全连接层与倒数第二个全连接层之间的参数,即保留绝大部分参数,适用于拥有图片较小的情况
2.训练所有参数,即使用网络思想不使用数据,适用于数据量较大
3.训练深层参数,即训练卷积层3、4、5,全连接层6、7、8。这也是最常见的形式
2 在tensorflow中进行微调
我们使用提供的图片,并将他们转换为tfrecord模式
我们使用命令 python data_convert.py -t data_prepare/pic/ --train-shards 2 --validation-shards 2 --num-threads 2 --dataset-name satellite
这里是生成训练用的数据及文本文档
在生成的过程中,发现书中提供代码中出现几处错误,主要体现在:
1.无法导入tfrecord.py,解决方法为将tfrecord和data_convert放在主目录下,并将pic/改为data_prepare/pic/
2.报错'range' object does not support item assignment,在tfrecord中339行更改为
shuffled_index = list(range(len(filenames)))
3.报错'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence,在tfrecord中160行更改为
with open(filename, 'rb') as f:
4.报错'RGB' has type <class 'str'>, but expected one of: ((<class 'bytes'>,),),在tfrecord中94 96行改为:
colorspace = b'RGB'
channels = 3
image_format = b'JPEG'
5.报错'urban' has type <class 'str'>, but expected one of: ((<class 'bytes'>,),)和
报错'76000_99449_18.jpg' has type <class 'str'>, but expected one of: ((<class 'bytes'>,),)
将tfrecord中219行左右处添加
text = text.encode()
filename = filename.encode()
6.报错File "F:\python\各种练习\项目3\tfrecord.py", line 146, in _is_png
return '.png' in filename
TypeError: a bytes-like object is required, not 'str'
将tfrecord中146行改为:
return b'.png' in filename
则现在没有任何错误,可以生成预定的两个训练集,两个验证集,一个.txt的类别文件