我正在TensorFlow包中提供的CIFAR10示例上运行SVHN数据集。我所做的只是改变数据的源目录,并在这里和那里修改几行代码。我可以成功地训练网络。
然而,当我运行svhn_eval.py(相当于cifar10_eval.py,名称已更改,因此我知道如何组织我的文件)时,我得到这个分配错误需要两个张量的形状匹配。我想问题可能是由于
saver.restore(sess, ckpt.model_checkpoint_path)
当跟踪结束并深入到TensorFlow的其他文件中时。有谁知道如何解决这个问题?
W tensorflow/core/common_runtime/executor.cc:1076] 0x1a5bad0 Compute status: Invalid argument: Assign requires shapes of both tensors to match. lhs shape= [2304,384] rhs shape= [4096,384]
[[Node: save/Assign_5 = Assign[T=DT_FLOAT, use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/cpu:0"](local3/weights, save/restore_slice_5)]]
Traceback (most recent call last):
File "/home/samuelchin/svhn/svhn_eval.py", line 161, 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 "/home/samuelchin/svhn/svhn_eval.py", line 157, in main
evaluate()
File "/home/samuelchin/svhn/svhn_eval.py", line 147, in evaluate
eval_once(saver, summary_writer, top_k_op, summary_op)
File "/home/samuelchin/svhn/svhn_eval.py", line 78, in eval_once
saver.restore(sess, ckpt.model_checkpoint_path)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 891, in restore
sess.run([self._restore_op_name], {self._filename_tensor_name: save_path})
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 373, in run
results = self._do_run(target_list, unique_fetch_targets, feed_dict_string)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 449, in _do_run
e.code)
tensorflow.python.framework.errors.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [2304,384] rhs shape= [4096,384]
[[Node: save/Assign_5 = Assign[T=DT_FLOAT, use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/cpu:0"](local3/weights, save/restore_slice_5)]]
Caused by op u'save/Assign_5', defined at:
File "/home/samuelchin/svhn/svhn_eval.py", line 161, 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 "/home/samuelchin/svhn/svhn_eval.py", line 157, in main
evaluate()
File "/home/samuelchin/svhn/svhn_eval.py", line 137, in evaluate
saver = tf.train.Saver(variables_to_restore)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 713, in __init__
restore_sequentially=restore_sequentially)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 432, in build
filename_tensor, vars_to_save, restore_sequentially, reshape)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 202, in _AddRestoreOps
validate_shape=not reshape))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 40, in assign
use_locking=use_locking, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 660, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1850, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1049, in __init__
self._traceback = _extract_stack()
编辑1:我更改的代码行是distorted_inputs。在最初的CIFAR10中,有一个从32x32到24x24图片的随机裁剪。但是,在SVHN实现中,我输入了32x32图像。根据输出错误,我们可以弄清楚出了什么问题。
lhs shape= [2304,384] rhs shape= [4096,384]
2304 = 24 * 24 * 4
4096 = 32 * 32 * 4
我们现在要问自己的问题是,为什么要乘以4?
答案 0 :(得分:1)
解决方案是cifar10.py有一个名为IMAGE_SIZE的变量。我把它留到了24,因为我认为它不会影响任何东西。但是,当您尝试运行测试集时,输入将被裁剪为IMAGE_SIZE x IMAGE_SIZE的大小。
因此,当没有改变时,张量尺寸不匹配。将该变量更改为32将起到作用。