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)

 

 

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐