tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

Variable "matching_filenames" @ tf.train.match_filenames_once() should be local?

Open keotic opened this issue 9 years ago • 9 comments

This var holds the matched file names for the input stream pipeline. Since it is added to the graph, when using the contractor of tf.train.Saver() it is saved as part of the checkpoint state. Hence loading saved models from checkpoints for inference, the training file names are loaded instead of the val / inference files.

Shouldn't this Var become a local variable? will it not be saved by default treated as local?

keotic avatar Jan 11 '17 11:01 keotic

Would it be possible for you to use tf.matching_files instead?

jart avatar Jan 13 '17 02:01 jart

@jart , I will give it a try, if this is the recommended method, the documentation at https://www.tensorflow.org/how_tos/reading_data/ should be changed.

keotic avatar Jan 13 '17 07:01 keotic

If I understand correctly, the goal of match_filenames_once is that it delegates to matching_files and then saves the result to checkpoints, so the operation only happens once. The documentation doesn't appear to be making any recommendations, so I'm not sure what is actionable here for TensorFlow. If you believe there is a bug in the software or documentation, let me know and I'll re-open this issue.

jart avatar Jan 13 '17 08:01 jart

There is not a bug, but it may cause undesired and unnoticed behavior in the following scenario:

  1. Use "match_filenames_once" to feed data in the training phase.

  2. Save model checkpoints with default 'tf.train.Saver()'

  3. Use again 'match_filenames_once' with a different pattern to load the inference / test files.

  4. Load previously saved model checkpoint for inference / test.

In this scenario, at step #4 the training files and not the test files will be loaded, since the old file list was loaded from the checkpoint.

Maybe a comment clarifying the issue should be added to the documentation.

keotic avatar Jan 13 '17 08:01 keotic

@dr4b Do you feel we should add further clarity to our documentation on loading models as @keotic is suggesting?

jart avatar Jan 13 '17 08:01 jart

Will this change in the API any time soon? And if not, sure, go ahead and add a comment?

dr4b avatar Jan 17 '17 06:01 dr4b

That seems like a footgun, a typical user might not expect match_filenames_once to be affected by checkpoint. A similar issue existed checkpoint affecting state of input pipelines that were affected by epochs variables, this was solved by making them local, as here

https://github.com/tensorflow/tensorflow/commit/4c85a95925a68fec324f70cd0d7f3d4548f97a38

yaroslavvb avatar Jan 17 '17 07:01 yaroslavvb

@keotic Is using your following steps right now? Will the correct queue be used at test time?

Use "match_filenames_once" to feed data in the training phase. Save model checkpoints with default 'tf.train.Saver()' Use again 'match_filenames_once' with a different pattern to load the inference / test files. Load previously saved model checkpoint for inference / test.

jiqiujia avatar Aug 24 '17 09:08 jiqiujia

@jiqiujia Should be OK if you are using latest versions of TF

keotic avatar Aug 27 '17 09:08 keotic