Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow Object Detection API ValueError: No variables to save

I'm trying to train a custom object detection model using tensorflow object detection api. For the training purposes I used pickled image data set for training and as model I used ssd_mobilenet_v1_coco. When I started the training it gave me this error.

Traceback (most recent call last):
  File "train.py", line 184, in <module>
    tf.app.run()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "train.py", line 180, in main
    graph_hook_fn=graph_rewriter_fn)
  File "/content/models/research/object_detection/trainer.py", line 381, in train
    init_saver = tf.train.Saver(available_var_map)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saver.py", line 1338, in __init__
    self.build()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saver.py", line 1347, in build
    self._build(self._filename, build_save=True, build_restore=True)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saver.py", line 1372, in _build
    raise ValueError("No variables to save")
ValueError: No variables to save

Full error code can find here...

[https://gist.github.com/mpgovinda/1f59f7de7873f6ec4c4426b79dc6827a][1]

How do I resolve this?

like image 391
Govinda Malavipathirana Avatar asked May 30 '18 08:05

Govinda Malavipathirana


3 Answers

🎉 Tested Solution

Add fine_tune_checkpoint_type: "detection" to train_config: { ... } section in your *.config file.

⭐ Sample

train_config: {
  ...
  fine_tune_checkpoint: "./pre_trained_model/model.ckpt"
  fine_tune_checkpoint_type:  "detection"
  ...
}

👨‍🔬 Tested on ssd_mobilenet_v1_quantized_300x300_coco14_sync model.

like image 130
Yedhrab Avatar answered Oct 13 '22 10:10

Yedhrab


Was training this model http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v2_coco_2018_03_29.tar.gz

Ran into the same error. Don't really like others' solution of setting from_detection_checkpoint: false.

Was fixed by adding the load_all_detection_checkpoint_vars: true field in train_config of the pipeline.config that comes with the model.

I also added from_detection_checkpoint: true as it was not there, not sure if it was relevant to the solution.

fine_tune_checkpoint: "path_to_model_ckpt/model.ckpt"
from_detection_checkpoint: true
load_all_detection_checkpoint_vars: true # this here fixed it
num_steps: 200000 # irrelevant
fine_tune_checkpoint_type: "detection"
like image 26
Joram Avatar answered Oct 13 '22 09:10

Joram


The latest models have this problem, to solve this:

Go to '.config' file of your model and in the training section change from_detection_checkpoint: true to false

It will work.

Happy Coding :)

like image 35
Abhiped Avatar answered Oct 13 '22 09:10

Abhiped