我在tensorflow
MNIST
示例管道中使用我自己的数据,但获得了:
ValueError:输入有16384个元素,不能被65536
整除
我一直在练习这个例子'数据成功。但是,在引入我自己调整为128x128px
并生成ubytes idx文件的图像后,我收到以下错误:
Traceback (most recent call last): File "tensorimage.py", line 132, in train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/training/optimizer.py", line 196, in minimize grad_loss=grad_loss) File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/training/optimizer.py", line 253, in compute_gradients colocate_gradients_with_ops=colocate_gradients_with_ops) File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/ops/gradients.py", line 478, in gradients in_grads = _AsList(grad_fn(op, *out_grads)) File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/ops/array_grad.py", line 298, in _ReshapeGrad return [array_ops.reshape(grad, array_ops.shape(op.inputs[0])), None] File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1758, in reshape name=name) File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op op_def=op_def) File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 2319, in create_op set_shapes_for_outputs(ret) File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 1711, in set_shapes_for_outputs shapes = shape_func(op) File "/home/ubuntu/tensorflow/python3/lib/python3.4/site-packages/tensorflow/python/ops/array_ops.py", line 1867, in _ReshapeShape (num_elements, known_elements)) ValueError: input has 16384 elements, which isn't divisible by 65536
令我感到困惑的是,我确实将输入设置为16384个元素(128x128),但是,我不知道65536来自何处。我梳理了所有代码,包括文件tensorflow/python3/lib/python3.4/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py
但无法找到65536号码的来源。
答案 0 :(得分:0)
如果没有看到更多代码到底出了什么问题,很难说清楚,但总结是TensorFlow认为input
的其他维度导致65536个元素的步幅,所以它试图推断出通过将已知尺寸大小的元素数除以缺少尺寸,并发现错误:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/array_ops.py#L1702
如果在此错误之前打印input
的大小会怎样?