gpt4 book ai didi

image-processing - 维度必须相等,但“SparseSoftmaxCrossEntropyWithLogits”为 1 和 128

转载 作者:行者123 更新时间:2023-11-30 08:37:55 24 4
gpt4 key购买 nike

我尝试使用 tensorflow 中的传统神经网络读取 png 格式的图像。我遇到了一个问题,我无法在读取数据步骤中处理标签,因此,它给了我一个错误。

我首先认为问题是在创建批队列和随机播放时发生的。这是 tf.train.shuffle_batch 中的问题,预期是 1-D,但实际上它的形状是 3-D。

我解决了这个问题。然后它在损失函数中给了我另一个错误

子代码是here

问题是::

Traceback (most recent call last): File "SVHN.py", line 280, in tf.app.run() File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "SVHN.py", line 269, in main train_op = SVHN_architecture_AND_optimize() File "SVHN.py", line 203, in SVHN_architecture_AND_optimize cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits = logits, labels = labels) File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py", line 1742, in sparse_softmax_cross_entropy_with_logits precise_logits, labels, name=name) File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 2418, in _sparse_softmax_cross_entropy_with_logits features=features, labels=labels, name=name) File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op op_def=op_def) File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2338, in create_op set_shapes_for_outputs(ret) File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1719, in set_shapes_for_outputs shapes = shape_func(op) File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1669, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn debug_python_shape_fn, require_shape_fn) File "/home/ashwaq/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 676, in _call_cpp_shape_fn_impl raise ValueError(err.message) ValueError: Dimensions must be equal, but are 1 and 128 for 'SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits' (op: 'SparseSoftmaxCrossEntropyWithLogits') with input shapes: [1,10], [128].

最佳答案

错误的原因是因为只有 1 个输入图像传递到 SparseSoftmaxEntropyWithLogits,而不是完整的批处理。此行导致了问题:

# change your single input `image` to a batch of `images`
images = tf.reshape(images, [-1, IMAGE_SIZE, IMAGE_SIZE, depth])

关于image-processing - 维度必须相等,但“SparseSoftmaxCrossEntropyWithLogits”为 1 和 128,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44979467/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com