问题描述
限时送ChatGPT账号..我使用的是 CIFAR10 示例.我用提供的代码训练了网络.培训顺利完成.由于我只想在我的数据集上评估每个示例一次,因此我将 cifar10_input.py 中的输入修改为以下内容.
I'm using the CIFAR10 example. I trained the net as it is with the code provided. The training was done successfully. As I wanted to evaluate each example only once on my data set, I have modified inputs in cifar10_input.py to the following.
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])
我已将问题隔离为以下几点:
I have isolated the problem to the following:
tf.train_string_input_producer([文件名], num_epochs = 1)
tf.train_string_input_producer([filename], num_epochs = 1)
如果我不设置 num_epochs = 1,则一切正常.如果我这样做,我会收到以下错误.
If I don't set num_epochs = 1, everything works fine as it is. If I do, I get the following error.
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:
EDIT 3 @mrry:
它仍然失败.这是踪迹.
It still fails. Here's the trace.
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:
EDIT 4 @mrry:
softmax_linear/biases/ExponentialMovingAverage
softmax_linear/biases/ExponentialMovingAverage
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:
EDIT 5 @mrry:
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)]]
推荐答案
TL;DR: 在 cifar10_eval.py
,将saver构造函数改为:
TL;DR: In cifar10_eval.py
, change the saver constructor so that it is:
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 时在内部创建一个变量(称为
"input_producer/limit_epochs/epochs"
)代码>.当,在 cifar10_eval.py
中有一个 tf.train.Saver
被创建,它使用 tf.all_variables()
,包括从 tf.nn.string_input_producer()
.这个变量列表决定了 TensorFlow 在检查点文件中查找的名称集.
This problem arises because tf.train.string_input_producer()
internally creates a variable (called "input_producer/limit_epochs/epochs"
) when its num_epochs
argument is not None
. When, in cifar10_eval.py
a tf.train.Saver
is created, it uses tf.all_variables()
, which includes the implicitly-created variable from the tf.nn.string_input_producer()
. This list of variables determines the set of names that TensorFlow looks up in the checkpoint file.
目前没有一个很好的方法来引用隐式创建的变量,除了它们的名字.因此,最好的解决方法是按名称从 Saver
构造函数中排除变量.
Currently there isn't a great way to refer to implicitly created variables, other than by their name. Therefore, the best fix is to exclude the variable from the Saver
constructor by name.
这篇关于计算状态:未找到:张量名称“input_producer/limit_epochs/epochs"在检查点文件中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论