models icon indicating copy to clipboard operation
models copied to clipboard

[deeplab]Can't run eval.py on my own dataset.

Open shipengai opened this issue 8 years ago • 19 comments

Hi,I have sovle this question many days.But I still can't solve it . I' m trying to finetune deeplab3+ with a new dataset (number of classes=18, ignore_label=255, Hight=width=450). I converted the dataset to tfrecords (training and validation) and started to train the model without problems using train.py. Now I want to evaluate the new checkpoint, running the evaluation script eval.py, and I obtain a shape of prediction error .


  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "/home/makbar/brett/wss-python/models/research/deeplab/eval.py", line 142, in main
    predictions, labels, dataset.num_classes, weights=weights)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/metrics_impl.py", line 1009, in mean_iou
    num_classes, weights)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/metrics_impl.py", line 263, in _streaming_confusion_matrix
    labels, predictions, num_classes, weights=weights, dtype=dtypes.float64)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/confusion_matrix.py", line 183, in confusion_matrix
    message='`predictions` out of bound')],
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/check_ops.py", line 579, in assert_less
    return control_flow_ops.Assert(condition, data, summarize=summarize)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/tf_should_use.py", line 118, in wrapped
    return _add_should_use_warning(fn(*args, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 177, in Assert
    guarded_assert = cond(condition, no_op, true_assert, name="AssertGuard")
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py", line 432, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2027, in cond
    orig_res_f, res_f = context_f.BuildCondBranch(false_fn)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 1868, in BuildCondBranch
    original_result = fn()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 175, in true_assert
    condition, data, summarize, name="Assert")
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_logging_ops.py", line 48, in _assert
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 3271, in create_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1650, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): assertion failed: [`predictions` out of bound] [Condition x < y did not hold element-wise:] [x (mean_iou/confusion_matrix/control_dependency_1:0) = ] [0 0 0...] [y (mean_iou/ToInt64_2:0) = ] [18]
	 [[Node: mean_iou/confusion_matrix/assert_less_1/Assert/AssertGuard/Assert = Assert[T=[DT_STRING, DT_STRING, DT_STRING, DT_INT64, DT_STRING, DT_INT64], summarize=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](mean_iou/confusion_matrix/assert_less_1/Assert/AssertGuard/Assert/Switch, mean_iou/confusion_matrix/assert_less_1/Assert/AssertGuard/Assert/data_0, mean_iou/confusion_matrix/assert_less_1/Assert/AssertGuard/Assert/data_1, mean_iou/confusion_matrix/assert_less_1/Assert/AssertGuard/Assert/data_2, mean_iou/confusion_matrix/assert_less_1/Assert/AssertGuard/Assert/Switch_1, mean_iou/confusion_matrix/assert_less_1/Assert/AssertGuard/Assert/data_4, mean_iou/confusion_matrix/assert_less_1/Assert/AssertGuard/Assert/Switch_2)]]```

The training script:
```python "${WORK_DIR}"/train.py \
  --logtostderr \
  --save_summaries_secs=100 \
  --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 \
  --train_crop_size=513 \
  --train_batch_size=4 \
  --training_number_of_steps="${NUM_ITERATIONS}" \
  --dataset="mydata" \
  --fine_tune_batch_norm=false \
  --tf_initial_checkpoint="${INIT_FOLDER}/deeplabv3_pascal_train_aug/model.ckpt" \
  --initialize_last_layer=false \
  --train_logdir="${TRAIN_LOGDIR}" \
  --dataset_dir="${NEW_DATASET}"```

The eval script:
```python "${WORK_DIR}"/eval.py \
  --logtostderr \
  --eval_split="validation" \
  --model_variant="xception_65" \
  --atrous_rates=6 \
  --atrous_rates=12 \
  --atrous_rates=18 \
  --output_stride=16 \
  --decoder_output_stride=4 \
  --eval_crop_size=450 \
  --eval_crop_size=450 \
  --dataset="mydata" \
  --checkpoint_dir="${TRAIN_LOGDIR}" \
  --eval_logdir="${EVAL_LOGDIR}" \
  --dataset_dir="${NEW_DATASET}" \
  --max_number_of_evaluations=1```

I have set ignore_label=255

shipengai avatar Apr 07 '18 13:04 shipengai

I have attempt eval_crop_size=[465,465] ,[513,513],[451,451].It occure same error. Besides, when run eval.py,I found the prediction have 255!so, the assert 'value< 18' can't pass. But,I use vis.py, save the prediction, it has no 255. I have run successfully deeplab on PASCAL VOC and citysacpe dataset.But,I can't run eval.py on my dataset, it make me so sad.

shipengai avatar Apr 08 '18 03:04 shipengai

Maybe you should check whether the data you built is correct. And "segmentation_dataset.py". I can't give any suggestion. Hope you solve your problem soon and share your experience.

hhwxxx avatar Apr 08 '18 10:04 hhwxxx

@hhwxxx what is your version of tensorflow

shipengai avatar Apr 08 '18 10:04 shipengai

@shipeng-uestc tensorflow1.6.0; python2.7

hhwxxx avatar Apr 08 '18 10:04 hhwxxx

@hhwxxx I found a possible error .In eval.py, the line 146. The API of tf.metric.mean_iou(labels, predictions).There are opposite,label is first,predictions is second

shipengai avatar Apr 08 '18 11:04 shipengai

@shipeng-uestc I am not sure, and I believe you have tested it. Maybe you can pull the latest version and run eval.py again, because the line you mentioned is 142 in the latest version(if you haven't added any code).

hhwxxx avatar Apr 08 '18 11:04 hhwxxx

@shipeng-uestc Have you solved the problem? Can you share your experience?

suphy2009 avatar Apr 11 '18 03:04 suphy2009

@suphy2009 I have solved the problem.Because my training data has some error。The code has no error.

shipengai avatar Apr 16 '18 08:04 shipengai

@shipeng-uestc Can you tell me what is your training data error? and how to modify it? I have the same problem with my own datasets when run eval.py .thanks

daxiaoshu avatar Apr 25 '18 08:04 daxiaoshu

I too am facing the same issue. Did anyone figure it out?

shivpatri avatar May 03 '18 10:05 shivpatri

@shivakshit try DrSleep's solution here Worked for me for training on MScocostuff

kkahatapitiya avatar May 08 '18 17:05 kkahatapitiya

@suphy2009 Hi! have you figured out what the problem it is?

ydt9000511 avatar May 14 '18 13:05 ydt9000511

The segmentation ground truth images in your custom dataset should have 1, 2, 3, ..., num_class grayscale value at each pixel (0 for background).

For example if you have 2 classes, you should use 1 and 2 for corresponding pixel . Of course the segmentation mask will look almost "black". If you choose, say 96 and 128, for your segmentation mask to make the it looks more human friendly, the network may end up predicting labels greater than num_class, which leads to the error in this issue.

BillBai avatar May 25 '18 09:05 BillBai

@BillBai

Should I make this change throughout all the dataset? Or just for validation and testing? It would not make much sense to change only the validation and test datasets, but in fact the masks become very difficult to analyze without contrast of the pixels.

Another question, I have only two classes, 0 being the background and 200 being the object that I want to segment, the number of classes should be 1 instead of 2? Or should I use the background as 1 and the object as 2 with 2 classes?

This is strange because the training seems to be running relatively well with the masks set to 0 and 200 with 2 classes.

felipecicero avatar Jun 13 '18 18:06 felipecicero

@kumara0093 I took a look at DrSleep's solution and I'm not sure how to implement it in the eval.py code. I'm looking at lines 125-132 in eval.py, is that the right spot?

kritiyer avatar Jul 10 '18 19:07 kritiyer

The segmentation ground truth images in your custom dataset should have 1, 2, 3, ..., num_class grayscale value at each pixel (0 for background).

For example if you have 2 classes, you should use 1 and 2 for corresponding pixel . Of course the segmentation mask will look almost "black". If you choose, say 96 and 128, for your segmentation mask to make the it looks more human friendly, the network may end up predicting labels greater than num_class, which leads to the error in this issue.

Since mask images are 8-bit png images, does this mean the max number of classes is 255? what if I have 1000 classes?

soulmachine avatar Jul 10 '19 07:07 soulmachine

@kumara0093 I took a look at DrSleep's solution and I'm not sure how to implement it in the eval.py code. I'm looking at lines 125-132 in eval.py, is that the right spot?

I'm having the same problem. Dr.Sleep's solution seems to only work with the code in his repository. Its unclear where to put it in the current version of Deeplab.

dgarnitz-zz avatar Jul 15 '19 11:07 dgarnitz-zz

@hhwxxx I found a possible error .In eval.py, the line 146. The API of tf.metric.mean_iou(labels, predictions).There are opposite,label is first,predictions is second

Hey guys, sorry that I'm addressing this issue again. I had the same problem and could solve it by applying the proposed solution. So far so good. However, I think that @hhwxxx is right and the two variables labels and predictions are reversed. What do you guys think about my concern? In the description of the function mean_iou we can clearly see the opposite. Or do I oversee something in the code?

ghost avatar Sep 26 '19 08:09 ghost

I just had this issue. I built custom labels on the Oxford-Pets dataset and I assigned the segmentation labels, which led to this error, as following: 2-background, 3-ignore, 5-cats, 10-dogs

I did the same thing as @BillBai explained. If you are building your own segmentation labels, tweak the data as following and it should fix it (it fixed it for me): 0-background, 1-cats, 2-dogs, 3-ignore

oss-vineet avatar Oct 28 '19 02:10 oss-vineet