DeepLabV3+训练自定义数据集实例(2)

7.注册数据集

在/models/research/deeplab/datasets 路径的data_generator.py 第93行copy该结构体:

_MYDATA_INFORMATION = DatasetDescriptor(
    splits_to_sizes={
        'train': 9,  # num of samples in images/training
        'val': 2,  # num of samples in images/validation
    },
    num_classes=2,       #共2类
    ignore_label=255,    #忽略第255类
)

然后找到 _DATASETS_INFORMATION ,加上mydata....一行

_DATASETS_INFORMATION = {
    'cityscapes': _CITYSCAPES_INFORMATION,
    'pascal_voc_seg': _PASCAL_VOC_SEG_INFORMATION,
    'ade20k': _ADE20K_INFORMATION,
    'mydata': _MYDATA_INFORMATION, 
}

如下图:

修改 deeplab\ utils\ train_utils.py,在210行处

exclude_list = ['global_step','logits'] #本来只有global_step ,现在加上 logits,表示不加载逻辑层的参数
  if not initialize_last_layer:
    exclude_list.extend(last_layers)

修改在models/research/deeplab/train.py里 165行左右

#Set to False if one does not want to re-use the trained classifier weights.

    flags.DEFINE_boolean('initialize_last_layer', False,
                         'Initialize the last layer.')
    
    flags.DEFINE_boolean('last_layers_contain_logits_only', True,
                         'Only consider logits as last layers or not.')

修改models/research/deeplab/input_preprocess.py  128行左右

  # Randomly crop the image and label.
  if is_training and label is not None:
    processed_image, label = preprocess_utils.random_crop(
        [processed_image, label], crop_height, crop_width)
  else:
    rr = tf.minimum(tf.cast(crop_height,tf.float32)/tf.cast(image_height,tf.float32),tf.cast(crop_width,tf.float32)/tf.cast(image_width,tf.float32))
    newh = tf.cast(tf.cast(image_height, tf.float32)*rr, tf.float32)
    neww = tf.cast((tf.cast(image_width, tf.float32)*rr), tf.float32)
    processed_image = tf.image.resize_images(processed_image, (newh, neww), method=tf.image.ResizeMethod.BILINEAR, align_corners=True)
    processed_image = preprocess_utils.pad_to_bounding_box(processed_image, 0, 0, crop_height, crop_width, mean_pixel)

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值