FCN训练自己的数据集

本文记录了使用FCN(全卷积网络)训练自己数据集的全过程,包括代码修改、数据集准备、标签图处理、参数配置、训练及结果可视化。主要问题涉及数据读取、图像尺寸和通道的匹配,以及标签值的范围限制。在训练后,通过可视化展示分类结果,并介绍了如何合成原始图像与预测图像来突出分类效果。
摘要由CSDN通过智能技术生成

        参考自用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,
评论 41
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值