Tensorflow:ValueError:单次检测时无法加载save_path

时间:2017-08-25 15:07:22

标签: tensorflow

我刚开始在python中使用tensorflow。我正在尝试使用tensorflow为pascalvoc数据集训练单次检测。在创建tfrecords时和使用VGG_VOC0712_SSD_300x300_ft_iter_120000.ckpt训练模型进行评估时,没有错误。然而,当我尝试使用ssd_300_vgg.ckpt预训练模型训练pascalvoc 2007或2012数据集时,我收到以下错误。

2017-08-25 20:03:03.001268: I tensorflow/core/common_runtime gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Quadro M5000M, pci bus id: 0000:01:00.0)
INFO:tensorflow:Error reported to Coordinator: <type 'exceptions.ValueError'>, Can't load save_path when it is None.
Traceback (most recent call last):
  File "train_ssd_network.py", line 391, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "train_ssd_network.py", line 387, in main
    sync_optimizer=None)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim/python/slim/learning.py", line 738, in train
    master, start_standard_services=False, config=session_config) as sess:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 965, in managed_session
    self.stop(close_summary_writer=close_summary_writer)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 793, in stop
    stop_grace_period_secs=self._stop_grace_secs)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/coordinator.py", line 389, in join
    six.reraise(*self._exc_info_to_raise)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 954, in managed_session
    start_standard_services=start_standard_services)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 709, in prepare_or_wait_for_session
    init_feed_dict=self._init_feed_dict, init_fn=self._init_fn)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/session_manager.py", line 281, in prepare_session
    init_fn(sess)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/variables.py", line 660, in callback
    saver.restore(session, model_path)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1558, in restore
    raise ValueError("Can't load save_path when it is None.")
ValueError: Can't load save_path when it is None.

我正在使用以下脚本来微调模型

DATASET_DIR=./tfrecords
TRAIN_DIR=./logs/
CHECKPOINT_PATH=./checkpoints/ssd_300_vgg.ckpt
python train_ssd_network.py \
    --train_dir=${TRAIN_DIR} \
    --dataset_dir=${DATASET_DIR} \
    --dataset_name=pascalvoc_2012 \
    --dataset_split_name=train \
    --model_name=ssd_300_vgg \
    --checkpoint_path=${CHECKPOINT_PATH} \
    --save_summaries_secs=60 \
    --save_interval_secs=600 \
    --weight_decay=0.0005 \
    --optimizer=adam \
    --learning_rate=0.001 \
    --batch_size=10

模型ssd_300_vgg.ckpt存储在./checkpoints

位置

如果有人有解决方案,请告诉我。

5 个答案:

答案 0 :(得分:6)

三点建议:

  • 检查恢复模型时的路径

    saver = tf.train.import_meta_graph(model_path)

  • 检查恢复检查点时的路径

    saver.restore(sess, tf.train.latest_checkpoint(cur_dir))

  • 保存模型时检查参数

    saver = tf.train.Saver(save_relative_paths=True)
    

答案 1 :(得分:2)

CHECKPOINT_PATH =。/检查点/ ssd_300_vgg.ckpt / ssd_300_vgg.ckpt

答案 2 :(得分:0)

检查您的路径,您可能指向一个不存在的文件。

答案 3 :(得分:0)

在检查这些答案时,人们可能想要的东西:

saver.restore(sess, tf.train.latest_checkpoint("directorytosavedmodel/./"))

换句话说,./在保存模型的目录中工作… (我一直在通过这种思路思考,我只是想还原一个模型,而不是在还原之前保存一个模型。)

答案 4 :(得分:0)

即使我证明正确的路径,我也遇到同样的问题。

我正在通过这样的正确路径:

sess =  tf.Session()
saver = tf.train.import_meta_graph('model_dir/model.meta')
restore = saver.restore(sess,tf.train.latest_checkpoint('model_dir/'))

但是我遇到了错误,所以我将检查点文件打开为.txt,检查点文件中的路径错误,这就是为什么它无法加载文件的原因。

因此,如果遇到相同的错误,请打开检查点文件路径。