为什么我在WiSe数据集中使用DeepLab v3+得到完整的零预测,即使损失不断减少?



我正在尝试在WiSe数据集(https://cvhci.anthropomatik.kit.edu/~mhaurile/wise/)上训练DeepLab v3+模型(https://github.com/tensorflow/models/research/deeplab/)。我已经修改了提供的脚本中的参数,并开始运行train.py脚本,但是即使损失一直在减少(从第10步的约2.7到第100步的约1.9),我在导出的检查点所做的预测中得到的结果都是零。甚至在每一张火车图像上,我都得到了一个全零的预测。
数据集信息(我已经处理了数据集以满足我的需要):
火车图像:1222
Val图像:100
总图像:1322
总类:9(包括背景)
类:['background', 'TitleSlide', 'PresTitle', 'ImageCaption', 'Image', 'Code', 'Enumeration', 'Tables', 'Paragraph']

我在datasets/data_generator.py中添加了以下代码:

_WISE_SEG_INFORMATION = DatasetDescriptor(
splits_to_sizes={
'train': 1222,
'trainval': 1322,
'val': 100,
},
num_classes=10,        # 8 foreground + 1 background + 1 ignore
ignore_label=255,
)
_DATASETS_INFORMATION = {
'cityscapes': _CITYSCAPES_INFORMATION,
'pascal_voc_seg': _PASCAL_VOC_SEG_INFORMATION,
'ade20k': _ADE20K_INFORMATION,
'wise_seg': _WISE_SEG_INFORMATION,
}

请注意,在我的数据集中,实际上没有图像具有标签为255的任何像素。每个标签的范围为[0,8]。我也试过将num_classes设置为9,但没有成功。
目录结构如下:

deeplab
├── datasets
│   ├── wise_seg
│   │   ├── exp
│   │   │   └── train_on_train_set
│   │   │       ├── eval
│   │   │       ├── export
│   │   │       ├── train
│   │   │       └── vis
│   │   ├── init_models
│   │   │   └── xception
|   |   |       ├── model.ckpt.data-00000-of-00001
|   |   |       └── model.ckpt.index
│   │   ├── tfrecord
│   │   └── WiSe
│   │       ├── Annotations
│   │       ├── ImageSets
│   │       │   └── Segmentation
|   |       |       ├── train.txt
|   |       |       ├── trainval.txt
|   |       |       └── val.txt
│   │       ├── JPEGImages
│   │       ├── SegmentationClass
│   │       └── SegmentationClassRaw
│   └── __pycache__
|------ Other stuff

我用来运行培训的命令:

python ./train.py 
--logtostderr 
--train_split="train" 
--model_variant="xception_65" 
--atrous_rates=6 
--atrous_rates=12 
--atrous_rates=18 
--output_stride=16 
--decoder_output_stride=4 
--train_crop_size="513,513" 
--train_batch_size=16 
--training_number_of_steps=30000 
--fine_tune_batch_norm=true 
--tf_initial_checkpoint="./datasets/wise_seg/init_models/xception/model.ckpt" 
--train_logdir="./datasets/wise_seg/train" 
--dataset="wise_seg" 
--initialize_last_layer=false 
--last_layers_contain_logits_only=false 
--dataset_dir="./datasets/wise_seg/tfrecord"

注意我已经设置了initialize_last_layer = Falselast_layers_contain_logits_only = False。我使用ImageNet预训练的exception -65模型作为骨干网络,我从这里给出的链接下载(具体来说,我使用xception_65_imagenet)。
我还在utils/train_utils.py中做了以下更改:

exclude_list = ['global_step', 'logits']
if not initialize_last_layer:
exclude_list.extend(last_layers)

当我执行训练时,它能够成功地到达训练部分,现在已经训练到110步左右。我使用以下命令导出了一个中间检查点:

python ./export_model.py 
--logtostderr 
--checkpoint_path="./datasets/wise_seg/exp/train_on_train_set/train/model.ckpt-41" 
--export_path="./datasets/wise_seg/exp/train_on_train_set/export/frozen_inference_graph-41.pb" 
--model_variant="xception_65" 
--atrous_rates=6 
--atrous_rates=12 
--atrous_rates=18 
--output_stride=16 
--decoder_output_stride=4 
--num_classes=${3} 
--crop_size=513 
--crop_size=513 
--inference_scales=1.0

检查点导出成功。然后,我尝试使用这里给出的示例笔记本来运行推断。具体来说,当我运行以下部分时,输出中会打印0:

graph_path = './datasets/wise_seg/exp/train_on_train_set/export/frozen_inference_graph-41.pb'
MODEL = DeepLabModel(graph_path)
resized_im, seg_map = MODEL.run(Image.open('./datasets/wise_seg/WiSe/JPEGImages/130110-3MQQHISL3D-540_frame11610.jpg'))
print(sum(sum(seg_map)))

对于任何给定的图像都是如此。为什么会发生这种情况?如有任何帮助,我将不胜感激。

你应该尝试110步以上的训练(最少2000步以上)。你的损失应该低于1.9。还请确保所标记的蒙版显示的像素值为0,1,2,3,4,…8. 另外,设置num_classes = 9也是正确的。

最新更新