Tensorflow:由于检查点文件无法训练我的模型

Tensorflow: Not able to train my model because of checkpoint file

我正在尝试设置 Tensorflow 的 Object Detection API and following this doc

我在训练我的模型时遇到以下错误(它抱怨找不到检查点文件,但它确实存在):

 python object_detection/train.py --logtostderr --pipeline_config_path=/c/ObjectDetection/models/model/faster_rcnn_resnet101_voc07_2.config --train_dir=/c/ObjectDetection/models/model/train
 INFO:tensorflow:Scale of 0 disables regularizer.
 INFO:tensorflow:Scale of 0 disables regularizer.
 INFO:tensorflow:Scale of 0 disables regularizer.
 INFO:tensorflow:Scale of 0 disables regularizer.
 INFO:tensorflow:Scale of 0 disables regularizer.
 INFO:tensorflow:Scale of 0 disables regularizer.
 INFO:tensorflow:Summary name Learning Rate is illegal; using Learning_Rate instead.
 Traceback (most recent call last):
   File "object_detection/train.py", line 198, in <module>
tf.app.run()
   File "C:\Python\Python35\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
   File "object_detection/train.py", line 194, in main
worker_job_name, is_chief, FLAGS.train_dir)
   File "C:\ObjectDetection\models\object_detection\trainer.py", line 218, in train
var_map, train_config.fine_tune_checkpoint))
   File "C:\ObjectDetection\models\object_detection\utils\variables_helper.py", line 122, in get_variables_available_in_checkpoint
ckpt_reader = tf.train.NewCheckpointReader(checkpoint_path)
   File "C:\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 118, in NewCheckpointReader
return CheckpointReader(compat.as_bytes(filepattern), status)
   File "C:\Python\Python35\lib\contextlib.py", line 66, in __exit__
next(self.gen)
   File "C:\Python\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
 tensorflow.python.framework.errors_impl.InvalidArgumentError: Unsuccessful TensorSliceReader constructor: Failed to get matching files on /c/ObjectDetection/faster_rcnn_resnet101_coco_11_06_2017/model.ckpt: Not found: FindFirstFile failed for: /c/ObjectDetection/faster_rcnn_resnet101_coco_11_06_2017 : The system cannot find the path specified.

我尝试了 Windows 和 Linux 两种格式的检查点文件路径,但出现以下错误:

Windows 格式路径 ('C:\ObjectDetectionaster_rcnn_resnet101_coco_11_06_2017\model.ckpt')

tensorflow.python.framework.errors_impl.InvalidArgumentError: Unsuccessful TensorSliceReader constructor: 
Failed to get matching files on C:\ObjectDetection
                          aster_rcnn_resnet101_coco_11_06_2017\model.ckpt: Invalid argument: 
FindFirstFile failed for: C:/ObjectDetection
           aster_rcnn_resnet101_coco_11_06_2017 : The filename, directory name, or volume label syntax is incorrect.

Linux 格式路径 ('/c/ObjectDetection/faster_rcnn_resnet101_coco_11_06_2017/model.ckpt')

tensorflow.python.framework.errors_impl.InvalidArgumentError: Unsuccessful TensorSliceReader constructor: 
Failed to get matching files on /c/ObjectDetection/faster_rcnn_resnet101_coco_11_06_2017/model.ckpt: Not found: 
FindFirstFile failed for: /c/ObjectDetection/faster_rcnn_resnet101_coco_11_06_2017 : The system cannot find the path specified.

正如您的错误消息所说,这是路径问题,而不是 TensorFlow 函数问题。

即使在 Git Bash 中,我也使用标准 windows 样式路径,即 'C:\' 而不是 '/c/'。此外,您需要转义 \ 或将其设为原始字符串。如:

'C:\ObjectDetection\faster_rcnn_resnet101_coco_11_06_2017\model.ckpt'
# or
r'C:\ObjectDetection\faster_rcnn_resnet101_coco_11_06_2017\model.ckpt'

请注意,在您粘贴的路径中,它显示 C:\ObjectDetectionaster_rcnn_... 而不是 C:\ObjectDetection\faster_rcnn_...。那是因为\f指的是转义序列:

>>> print('\f')


>>> ord('\f')
12
>>> print('\f')  # escape the slash
\f
>>> print(r'\f')  # or use raw strings with the 'r' prefix
\f