models icon indicating copy to clipboard operation
models copied to clipboard

Unable to train CenterNet MobileNetV2 FPN with transfer learning

Open ArdelIndyme opened this issue 5 years ago • 5 comments

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • [ x] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • [ x] I am reporting the issue to the correct repository. (Model Garden official or research directory)
  • [x ] I checked to make sure that this issue has not already been filed.

1. The entire URL of the file you are using

http://download.tensorflow.org/models/object_detection/tf2/20210210/centernet_mobilenetv2fpn_512x512_coco17_od.tar.gz

2. Describe the bug

I am trying to train the centernet_mobilenetv2_fpn_od using the following tutorial: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html#preparing-the-workspace I used this tutorial previously to train ssd_mobilenet_v2 and it worked fine. I followed the same steps for centernet, but I recieve the following error:

tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[0] = 0 is not in [0, 0)

3. Steps to reproduce

Follow this guide: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html#preparing-the-workspace but using the centernet_mobiletv2 model form the model zoo.

4. Expected behavior

CenterNet trains through transfer learning.

5. Additional context

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/context.py", line 2113, in execution_mode
    yield
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/data/ops/iterator_ops.py", line 733, in _next_internal
    output_shapes=self._flat_output_shapes)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/gen_dataset_ops.py", line 2579, in iterator_get_next
    _ops.raise_from_not_ok_status(e, name)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py", line 6862, in raise_from_not_ok_status
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[0] = 0 is not in [0, 0)
	 [[{{node GatherV2_8}}]]
	 [[MultiDeviceIteratorGetNextFromShard]]
	 [[RemoteCall]] [Op:IteratorGetNext]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "model_main_tf2.py", line 113, in <module>
    tf.compat.v1.app.run()
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 303, in run
    _run_main(main, args)
  File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "model_main_tf2.py", line 110, in main
    record_summaries=FLAGS.record_summaries)
  File "/content/drive/.shortcut-targets-by-id/1MNY3RVQFiMLhbbLGrZjkYHlMWIQeK7FY/Colab Notebooks/Tensorflow/workspace/training_demo/object_detection/model_lib_v2.py", line 597, in train_loop
    train_input, unpad_groundtruth_tensors)
  File "/content/drive/.shortcut-targets-by-id/1MNY3RVQFiMLhbbLGrZjkYHlMWIQeK7FY/Colab Notebooks/Tensorflow/workspace/training_demo/object_detection/model_lib_v2.py", line 392, in load_fine_tune_checkpoint
    _ensure_model_is_built(model, input_dataset, unpad_groundtruth_tensors)
  File "/content/drive/.shortcut-targets-by-id/1MNY3RVQFiMLhbbLGrZjkYHlMWIQeK7FY/Colab Notebooks/Tensorflow/workspace/training_demo/object_detection/model_lib_v2.py", line 155, in _ensure_model_is_built
    features, labels = iter(input_dataset).next()
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/input_lib.py", line 628, in next
    return self.__next__()
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/input_lib.py", line 632, in __next__
    return self.get_next()
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/input_lib.py", line 663, in get_next
    self._iterators[i].get_next_as_list_static_shapes(new_name))
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/input_lib.py", line 1619, in get_next_as_list_static_shapes
    return self._format_data_list_with_options(self._iterator.get_next())
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/data/ops/multi_device_iterator_ops.py", line 585, in get_next
    result.append(self._device_iterators[i].get_next())
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/data/ops/iterator_ops.py", line 800, in get_next
    return self._next_internal()
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/data/ops/iterator_ops.py", line 739, in _next_internal
    return structure.from_compatible_tensor_list(self._element_spec, ret)
  File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/context.py", line 2116, in execution_mode
    executor_new.wait()
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/executor.py", line 69, in wait
    pywrap_tfe.TFE_ExecutorWaitForAllPendingNodes(self._handle)
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[0] = 0 is not in [0, 0)
	 [[{{node GatherV2_8}}]]
	 [[MultiDeviceIteratorGetNextFromShard]]
	 [[RemoteCall]]

6. System information

running on Google Collab. the following is installed before training:

  • tf_slim
  • lvis
  • tf-models-official
  • tensorflow-gpu

python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)" yeilds:

v2.4.1-0-g85c8b2a817f 2.4.1

ArdelIndyme avatar May 03 '21 17:05 ArdelIndyme

Can you share your share your full config file?

mrinal18 avatar May 03 '21 18:05 mrinal18

Can you share your share your full config file?

model {
  center_net {
    num_classes: 1
    feature_extractor {
      type: "mobilenet_v2_fpn_sep_conv"
    }
    image_resizer {
      keep_aspect_ratio_resizer {
        min_dimension: 512
        max_dimension: 512
        pad_to_max_dimension: true
      }
    }
    use_depthwise: true
    object_detection_task {
      task_loss_weight: 1.0
      offset_loss_weight: 1.0
      scale_loss_weight: 0.1
      localization_loss {
        l1_localization_loss {
        }
      }
    }
    object_center_params {
      object_center_loss_weight: 1.0
      classification_loss {
        penalty_reduced_logistic_focal_loss {
          alpha: 2.0
          beta: 4.0
        }
      }
      min_box_overlap_iou: 0.7
      max_box_predictions: 20
    }
  }
}
train_config {
  batch_size: 128
  data_augmentation_options {
    random_horizontal_flip {
      keypoint_flip_permutation: 0
      keypoint_flip_permutation: 2
      keypoint_flip_permutation: 1
      keypoint_flip_permutation: 4
      keypoint_flip_permutation: 3
      keypoint_flip_permutation: 6
      keypoint_flip_permutation: 5
      keypoint_flip_permutation: 8
      keypoint_flip_permutation: 7
      keypoint_flip_permutation: 10
      keypoint_flip_permutation: 9
      keypoint_flip_permutation: 12
      keypoint_flip_permutation: 11
      keypoint_flip_permutation: 14
      keypoint_flip_permutation: 13
      keypoint_flip_permutation: 16
      keypoint_flip_permutation: 15
    }
  }
  data_augmentation_options {
    random_patch_gaussian {
    }
  }
  data_augmentation_options {
    random_crop_image {
      min_aspect_ratio: 0.5
      max_aspect_ratio: 1.7
      random_coef: 0.25
    }
  }
  data_augmentation_options {
    random_adjust_hue {
    }
  }
  data_augmentation_options {
    random_adjust_contrast {
    }
  }
  data_augmentation_options {
    random_adjust_saturation {
    }
  }
  data_augmentation_options {
    random_adjust_brightness {
    }
  }
  data_augmentation_options {
    random_absolute_pad_image {
      max_height_padding: 200
      max_width_padding: 200
      pad_color: 0.0
      pad_color: 0.0
      pad_color: 0.0
    }
  }
  optimizer {
    adam_optimizer {
      learning_rate {
        cosine_decay_learning_rate {
          learning_rate_base: 5e-3
          total_steps: 300000
          warmup_learning_rate: 1e-4
          warmup_steps: 5000
        }
      }
    }
    use_moving_average: false
  }
  num_steps: 300000
  max_number_of_boxes: 8
  unpad_groundtruth_tensors: false
  fine_tune_checkpoint: "pre-trained-models/centernet_mobilenetv2_fpn_od/checkpoint/ckpt-0" # Path to checkpoint of pre-trained model
  fine_tune_checkpoint_type: "detection"
  fine_tune_checkpoint_version: V2
}
train_input_reader {
  label_map_path: "annotations/label_map.pbtxt"
  tf_record_input_reader {
    input_path: "annotations/train.record"
  }
  filenames_shuffle_buffer_size: 256
  num_keypoints: 17
}
eval_config {
  num_visualizations: 10
  metrics_set: "coco_detection_metrics"
  use_moving_averages: false
  min_score_threshold: 0.3
  max_num_boxes_to_visualize: 8
  batch_size: 1
}
eval_input_reader {
  label_map_path: "annotations/label_map.pbtxt"
  shuffle: false
  num_epochs: 1
  tf_record_input_reader {
    input_path: "annotations/test.record"
  }
  num_keypoints: 17
}

ArdelIndyme avatar May 04 '21 15:05 ArdelIndyme

Hi, I am facing the same issue with very similar config file. tf version: 2.4.1 I run it on google collab

Paliking avatar May 05 '21 16:05 Paliking

Can you check my comment at #9785 ant try it? https://github.com/tensorflow/models/issues/9785#issuecomment-827240133

After training 300k steps, train loss reached to around 1.2 but it detects nothing...

mah110mat avatar May 11 '21 00:05 mah110mat

Can you check my comment at #9785 ant try it? #9785 (comment)

After training 300k steps, train loss reached to around 1.2 but it detects nothing...

this helped, it is working for me now. It would be great if someone could put the working/recommended config here : https://github.com/tensorflow/models/tree/master/research/object_detection/configs/tf2

thank you

Paliking avatar May 14 '21 14:05 Paliking