参考自用FCN训练自己数据集,在此记录调试代码的过程,仅供参考。
1 代码修改
这部分是记录我对原代码修改的过程。
原代码中read_MITSceneParsingData.py中read_dataset()函数需要进行修改,否则会报错“module 'TensorflowUtils' has no attribute 'maybe_download_and_extract' ”。修改如下:
def read_dataset(data_dir, data_name):
pickle_filename = "MITSceneParsing.pickle"
pickle_filepath = os.path.join(data_dir, pickle_filename)
result = create_image_lists(os.path.join(data_dir, data_name))
print("Pickling ...")
with open(pickle_filepath, 'wb') as f:
pickle.dump(result, f, pickle.HIGHEST_PROTOCOL)
with open(pickle_filepath, 'rb') as f: # 打开pickle文件
result = pickle.load(f)
training_records = result['training']
validation_records = result['validation']
del result
return training_records, validation_records
原代码中BatchDatsetReader.py中_transform()函数需要进行修改,否则会报错could not broadcast input array from shape (256,256,3,1) into shape (256,256,1),修改代码如下。另外,还需要from PIL import Image。报错的原因是label图像用misc.imread()读取后形状是(256,256,3),而用Image.open()读取后形状(256,256),但是label图像深度只有8位,而非24位,不应该有3层深度,所以应该选择Image.open()方法读取。此外,_transform()函数中对2维图像扩展为3维好像也没什么用处,我就删掉了。
def _transform(self, filename):
image = Image.open(filename)
if self.image_options.get("resize", False) and self.image_options["resize"]:
resize_size = int(self.image_options["resize_size"])
resize_image = misc.imresize(image, [resize_size,