models icon indicating copy to clipboard operation
models copied to clipboard

Could only save 5 checkpoints w/ model_main.py

Open YijinLiu opened this issue 8 years ago • 21 comments

System information

  • What is the top-level directory of the model you are using: research/object_detection
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04
  • TensorFlow installed from (source or binary): Source
  • TensorFlow version (use command below): 1.10
  • Bazel version (if compiling from source): 0.15.2
  • CUDA/cuDNN version: 9.2/7.1.4.18
  • GPU model and memory: GTX 960/4G
  • Exact command to reproduce: python tf_models/research/object_detection/model_main.py --alsologtostderr
    --pipeline_config_path=ssdlite_mobilenet_v2_coco.config --model_dir=XXX

Describe the problem

Looks like the new model_main.py hardcodes many parameters. It simply ignores keep_checkpoint_every_n_hours. In another bug, it only exports one image to tensorboard, ignoring num_visualizations.

YijinLiu avatar Aug 13 '18 06:08 YijinLiu

https://www.tensorflow.org/api_docs/python/tf/train/Saver#init you can use tf.train.Saver(max_to_keep=None) to save all checkpoints when you use legacy/trainer.py

irmowan avatar Aug 15 '18 07:08 irmowan

@irmowan do you mean the one on line 408 in model_lib.py? Adding max_to_keep=None to this one has no effect.

yu-jingrui avatar Sep 11 '18 06:09 yu-jingrui

@irmowan check issue #5139. With tf r1.10 it can be set in model_main.py

yu-jingrui avatar Sep 11 '18 08:09 yu-jingrui

@YijinLiu @fisheess Do you fix this issue? I have the same problem.

lan2720 avatar Sep 13 '18 07:09 lan2720

@pkulzc Hi, how to set max_to_keep=None. I have changed all tf.train.Saver(max_to_keep=None) in object_detection project, but it's still not working.

lan2720 avatar Sep 13 '18 07:09 lan2720

@lan2720 It is solved. With the latest tensorflow you need to set the parameters in model_main.py. Check #5139. You need to add keep_checkpoint_max=None to line 59 config = tf.estimator.RunConfig(...)

yu-jingrui avatar Sep 13 '18 08:09 yu-jingrui

@lan2720 you can check documents on tf.estimator.RunConfig to get more information. @YijinLiu I think it is time to close this issue since it is already solved.

yu-jingrui avatar Sep 13 '18 08:09 yu-jingrui

@fisheess Thank you! It works.

lan2720 avatar Sep 13 '18 09:09 lan2720

@fisheess 's method works for me.

YijinLiu avatar Oct 04 '18 04:10 YijinLiu

Also check this: https://stackoverflow.com/a/51858873/8407621

saeedarabi92 avatar Dec 25 '18 01:12 saeedarabi92

Sigh, it's broken again after I synced to the latest code... It's caused by https://github.com/tensorflow/models/commit/a1337e01db4e3a54c48d2fbd6614c772bdf0f4c5#diff-76df8ca264a059e8a3003851fe4d7849R474 You'll need to add a max_to_keep parameter.

YijinLiu avatar Jan 05 '19 11:01 YijinLiu

With the latest code, I had to add max_to_keep to RunConfig in model_main.py as well as to tf.train.Saver in model_lib.py then it worked

NPetsky avatar Jan 11 '19 09:01 NPetsky

@YijinLiu @NPetsky do you mean keep_checkpoint_max has no effect now? Then I need to set max_to_keep=None and max_to_keep=None in both files? I will try it out.

yu-jingrui avatar Feb 08 '19 21:02 yu-jingrui

@fisheess yes, adding max_to_keep only in model_main.py had no effect for me

NPetsky avatar Feb 12 '19 09:02 NPetsky

@NPetsky max_to_keep is not a valid argument for RunConfig (https://www.tensorflow.org/api_docs/python/tf/estimator/RunConfig) Adding keep_checkpoint_max to tf.estimator.RunConfig in model_main.py and max_to_keep to tf.train.Saver in model_lib.py works

kulkarnivishal avatar May 08 '19 21:05 kulkarnivishal

@kulkarnivishal is right, please set keep_checkpoint_max in RunConfig.

pkulzc avatar Jun 26 '19 20:06 pkulzc

Thank you @kulkarnivishal It worked for me too. I made following two changes

  1. keep_checkpoint_max=500 on model_main.py config = tf.estimator.RunConfig(model_dir=FLAGS.model_dir, keep_checkpoint_max=500)
  2. max_to_keep=500 on model_lib.py(added on two places)
saver = tf.train.Saver(
	variables_to_restore,
	keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours,
	max_to_keep=500)# <= added max_to_keep argument here
	
	
saver = tf.train.Saver(
	sharded=True,
	keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours,
	save_relative_paths=True,
	max_to_keep=500)# <= added max_to_keep argument here

prempatra avatar Aug 09 '19 02:08 prempatra

@prempatra This works perfectly, thanks.

surfii3z avatar Oct 30 '19 05:10 surfii3z

Thank you @kulkarnivishal It worked for me too. I made following two changes

  1. keep_checkpoint_max=500 on model_main.py config = tf.estimator.RunConfig(model_dir=FLAGS.model_dir, keep_checkpoint_max=500)
  2. max_to_keep=500 on model_lib.py(added on two places)

saver = tf.train.Saver( variables_to_restore, keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours, max_to_keep=500)# <= added max_to_keep argument here

saver = tf.train.Saver( sharded=True, keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours, save_relative_paths=True, max_to_keep=500)# <= added max_to_keep argument here

it didn't work for deeplab. Does anyone know how to save more checkpoints during training deeplab network instead of the object-detection network?

zheyuanWang avatar Dec 10 '19 21:12 zheyuanWang

it's in export_model.py

change the line to: saver = tf.train.Saver(tf.all_variables().append(max_to_keep=50)) #saver = tf.train.Saver(tf.all_variables())

in order to keep lastest 50 checkpoints

zheyuanWang avatar Jun 22 '20 15:06 zheyuanWang