简体   繁体   English

Tensorflow:ValueError:在单次检测中为 None 时无法加载 save_path

[英]Tensorflow: ValueError: Can't load save_path when it is None in single shot detection

I have just started working with tensorflow in python. I am trying to train Single shot detection using tensorflow for pascalvoc dataset.我刚刚开始在 python 中使用 tensorflow。我正在尝试使用 tensorflow 为 pascalvoc 数据集训练单发检测。 While creating tfrecords and during evaluation using VGG_VOC0712_SSD_300x300_ft_iter_120000.ckpt trained model there was no error.在创建 tfrecords 和评估期间使用 VGG_VOC0712_SSD_300x300_ft_iter_120000.ckpt 训练 model 没有错误。 Whereas, when I am trying to train pascalvoc 2007 or 2012 datasets using ssd_300_vgg.ckpt pre-trained model I am getting following error.然而,当我尝试使用 ssd_300_vgg.ckpt 预训练 model 训练 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.

I am using following script to fine-tune the model我正在使用以下脚本微调 model

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

The model ssd_300_vgg.ckpt is stored at the location./checkpoints model ssd_300_vgg.ckpt 存储在位置./checkpoints

Please let me know if anyone has the solution.如果有人有解决方案,请告诉我。

Three suggestions:三点建议:

  • Check the path when restoring the model恢复模型时检查路径

    saver = tf.train.import_meta_graph(model_path)

  • Check the path when restoring the checkpoint还原检查点时检查路径

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

  • Check the parameters when saving the model保存模型时检查参数

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

CHECKPOINT_PATH=./checkpoints/ssd_300_vgg.ckpt/ssd_300_vgg.ckpt

I was having the same problem even when I was proving correct path.即使我证明了正确的路径,我也遇到了同样的问题。

I was passing the correct path like this :我正在通过这样的正确路径:

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

But I was getting the error, so I opened checkpoint file as .txt, the path in checkpoint file was wrong that's why it was not able to load the file.但是我遇到了错误,所以我将检查点文件作为 .txt 打开,检查点文件中的路径是错误的,这就是它无法加载文件的原因。

So if you are getting the same error, check the checkpoint file path by opening it.因此,如果您遇到相同的错误,请通过打开检查点文件路径来检查它。

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

What someone might want, when checking through those answers:在检查这些答案时,有人可能想要什么:

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

in other words the ./ works in the directory the model is saved… (I was looking through this thread thinking, I just want to restore a model not save one before I restore..)换句话说, ./在保存模型的目录中工作......(我正在通过这个线程思考,我只想恢复一个模型而不是在我恢复之前保存一个模型......)

It means that model files are not there and saver.restore can't read the model files.这意味着 model 文件不存在并且saver.restore无法读取 model 文件。

Sometimes (In my case), you cloned a repo, but you forgot to download pretrained model and locate them in the path saver.restore pointing to.有时(在我的例子中),你克隆了一个 repo,但你忘记下载预训练的pretrained model并在saver.restore指向的路径中找到它们。

(If you save them in you'r code by yourself, see @Maikefer answer) (如果你自己将它们保存在你的代码中,请参阅@Maikefer 答案)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:传递的 save_path 不是有效的检查点:modeltest.ckpt - ValueError: The passed save_path is not a valid checkpoint: modeltest.ckpt 文件“ test_hdfs.py”,save_path = saver.save(sess,hdfs_path +“ save_net.ckpt”)“ {}的父目录不存在,无法保存。”。format(save_path)) - File “test_hdfs.py”, save_path = saver.save(sess, hdfs_path+“save_net.ckpt”) “Parent directory of {} doesn't exist, can't save.”.format(save_path)) ValueError:传递的保存路径不是有效的检查点:/content/gdrive/My Drive\model\20191003053122/variables/variables - ValueError: The passed save_path is not a valid checkpoint: /content/gdrive/My Drive\model\20191003053122/variables/variables TENSORFLOW 找不到解决方案:ValueError: logits and labels must have the same shape ((None, 1) vs (None, 2, 2)) - TENSORFLOW Can't find a solution for: ValueError: logits and labels must have the same shape ((None, 1) vs (None, 2, 2)) Tensorflow 和 Keras 无法加载 .ckpt 保存 - Tensorflow & Keras can't load .ckpt save ValueError:保存Tensorflow检查点时无需保存变量 - ValueError: No variables to save when saving Tensorflow checkpoint ValueError: got_ver 在导入 Tensorflow 时为 None - ValueError: got_ver is None when importing Tensorflow [Tensorflow] [物体检测]尝试使用--num_clones = 2训练时的ValueError - [Tensorflow][Object detection] ValueError when try to train with --num_clones=2 Tensorflow:ValueError:形状(None,1)和(None,2)不兼容 - Tensorflow: ValueError: Shapes (None, 1) and (None, 2) are incompatible TensorFlow - ValueError:形状(无,1)和(无,10)不兼容 - TensorFlow - ValueError: Shapes (None, 1) and (None, 10) are incompatible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM