在语义分割中我们常用的数据集是VOC2012,在实际训练的时候我们如何利用这个数据集对模型进行训练呢,下面是处理的一些细节以及相关代码。这个数据集的介绍详细请见我的另一篇博客
用tensorflow对其进行处理
tensorflow读图片的方式:
import tensorflow as tf
img_content = tf.read_file(filepath)
img = tf.image.decode_image(img_content)
# tf.image.decode_image()会根据读入的图片的channel数
# 分别等价于 tf.image.decode_png() channel=1
# tf.image.decode_jpeg() channel=3
# tf.image.decode_gif() channel=4
1.如果直接从SegmentationClass里面读.png图片,打印其ndarray,会发现你读出来的ndarray里面最大的数值居然是220。而原本应该是255(SegmentationClass里面的图片的边缘是白色)。并且并不能读出正确的分类信息。这个时候要先用skimage来对图片做一次转换。转换代码如下: