首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >计算状态:未找到:检查点文件中未找到张量名称“input_ files /files_epochs/epochs”

计算状态:未找到:检查点文件中未找到张量名称“input_ files /files_epochs/epochs”
EN

Stack Overflow用户
提问于 2016-02-27 18:59:38
回答 2查看 1.6K关注 0票数 1

我正在使用CIFAR10示例。我用所提供的代码训练了网络。训练成功了。由于我只想在我的数据集中对每个示例进行一次评估,所以我将cifar10_input.py中的输入修改为以下内容。

代码语言:javascript
复制
def inputs(eval_data, data_dir, batch_size):
  filename = os.path.join(data_dir, TEST_FILE)
  filename_queue = tf.train.string_input_producer([filename],num_epochs=1)
  image, label = read_and_decode(filename_queue)
  float_image = tf.image.per_image_whitening(image)
  min_fraction_of_examples_in_queue = 0.4
  min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_EVAL *
                           min_fraction_of_examples_in_queue)
  images, label_batch = tf.train.batch(
      [image, label],
      batch_size=batch_size,
      num_threads=1,
      capacity=min_queue_examples + 3 * batch_size)

  tf.image_summary('images', images)
  return images, tf.reshape(label_batch, [batch_size])

我把这个问题分为以下几点:

Tf.train_string_input_producer(文件名,num_epochs = 1)

如果我不设置num_epochs = 1,那么一切都会正常工作。如果我这样做了,我会得到以下错误。

代码语言:javascript
复制
0x2cf2700 Compute status: Not found: Tensor name "input_producer/limit_epochs/epochs" not found in checkpoint files /home/jkschin/tensorflow/my_code/data/svhn/train/model.ckpt-8000

谢谢你的帮助!

编辑3 @mrry:

但还是失败了。这是痕迹。

代码语言:javascript
复制
Traceback (most recent call last):
  File "cnn_eval.py", line 148, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/default/_app.py", line 30, in run
    sys.exit(main(sys.argv))
  File "cnn_eval.py", line 144, in main
    evaluate()
  File "cnn_eval.py", line 119, in evaluate
    saver = tf.train.Saver([v for v in variables_to_restore if v.name != "input_producer/limit_epochs/epochs"])
AttributeError: 'unicode' object has no attribute 'name'

编辑4 @mrry:

softmax_linear/biases/ExponentialMovingAverage

代码语言:javascript
复制
conv2/biases/ExponentialMovingAverage
local4/biases/ExponentialMovingAverage
local3/biases/ExponentialMovingAverage
softmax_linear/weights/ExponentialMovingAverage
conv1/biases/ExponentialMovingAverage
local4/weights/ExponentialMovingAverage
conv2/weights/ExponentialMovingAverage
input_producer/limit_epochs/epochs
local3/weights/ExponentialMovingAverage
conv1/weights/ExponentialMovingAverage

Traceback (most recent call last):
  File "cnn_eval.py", line 148, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/default/_app.py", line 30, in run
    sys.exit(main(sys.argv))
  File "cnn_eval.py", line 144, in main
    evaluate()
  File "cnn_eval.py", line 119, in evaluate
    saver = tf.train.Saver([v for v in variables_to_restore if v != "input_producer/limit_epochs/epochs"])
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 784, in __init__
    restore_sequentially=restore_sequentially)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 437, in build
    vars_to_save = self._ValidateAndSliceInputs(names_to_variables)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 340, in _ValidateAndSliceInputs
    names_to_variables = self._VarListToDict(names_to_variables)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 314, in _VarListToDict
    raise TypeError("Variable to save is not a Variable: %s" % var)
TypeError: Variable to save is not a Variable: Tensor("Const:0", shape=(), dtype=string)

编辑5 @mrry:

代码语言:javascript
复制
saver = tf.train.Saver([tf.Variable(0.0,validate_shape=False,name=v) for v in variables_to_restore if v != "input_producer/limit_epochs/epochs"])

0x21d0cb0 Compute status: Invalid argument: Assign requires shapes of both tensors to match. lhs shape= [] rhs shape= [10]
     [[Node: save/Assign_8 = Assign[T=DT_FLOAT, use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/gpu:0"](softmax_linear/biases/ExponentialMovingAverage, save/restore_slice_8/_20)]]
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-27 21:31:20

TL;DR: In cifar10_eval.py,将保护程序构造函数更改为:

代码语言:javascript
复制
saver = tf.train.Saver([v for v in variables_to_restore
                        if v != "input_producer/limit_epochs/epochs"])

之所以会出现这个问题,是因为当tf.train.string_input_producer()num_epochs参数不是None时,num_epochs内部会创建一个变量(称为None)。在cifar10_eval.py a is created中,它使用tf.all_variables(),其中包括从tf.nn.string_input_producer()中隐式创建的变量。此变量列表确定TensorFlow在检查点文件中查找的名称集。

目前没有一种很好的方法来引用隐式创建的变量,除了它们的名称。因此,最好的解决办法是按名称从Saver构造函数中排除变量。

票数 3
EN

Stack Overflow用户

发布于 2016-08-09 14:27:37

消除隐式变量"input_producer/limit_epochs/epochs"的另一种方法是只加载可训练变量:

代码语言:javascript
复制
saver = tf.train.Saver(tf.trainable_variables())
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35674073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档