Fix NotFoundError error in tensorflow test model
- 2020-11-18 06:18:31
- OfStack
The error code is as follows:
NotFoundError (see above for traceback): Unsuccessful TensorSliceReader constructor:
Failed to find any matching files for xxx
...
After data analysis, the cause of the error may be the path problem when loading the model. The loading model method I adopted:
with tf.Session() as sess:
print("Reading checkpoints...")
ckpt = tf.train.get_checkpoint_state(logs_train_dir)
if ckpt and ckpt.model_checkpoint_path:
global_step = ckpt.model_checkpoint_path.split('/') [-1].split('-')[-1]
saver.restore(sess, ckpt.model_checkpoint_path)
print('Loading success, global_step is %s' % global_step)
else:
print('No checkpoint file found')
When the model is saved, the method is
saver = tf.train.Saver()
...
...
...
if step % 1000 == 0 or (step + 1) == MAX_STEP:
checkpoint_path = os.path.join(logs_train_dir, './model.ckpt')
saver.save(sess, checkpoint_path, global_step=step)
Note the./ model.ckpt in the code block, this is the key, model.ckpt will report an error. If the method of directly loading the model file is adopted when loading the model, then:
Change the previous code:
saver.restore(sess,'model.ckpt')
Modified code:
saver.restore(sess,'./model.ckpt')
After my modification, there is no problem. If this method cannot solve your problem, please check the data and solve it