3
votes

I tried to read an images as png format using conventional neural network in tensorflow. I faced a problem that I cannot deal with label in read data step, so, it gives me an error.

First thing I thought the problem is happened when I create batch queue and shuffle. which was the problem in tf.train.shuffle_batch expected 1-D but actually it got shape as 3-D.

I fixed that. and then it gives me another error in loss function

The subcode is here

the problem is::

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].

2

2 Answers

0
votes

The reason for the error is because only 1 input image is getting passed to the SparseSoftmaxEntropyWithLogits and not a complete batch. This line is causing the problem:

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

I can't view your code (link doesn't work or the dropbox file isn't public) but based on the error, your labels are the wrong shape. For SparseSoftmaxCrossEntropyWithLogits the labels should be shaped [None,], where None is the batch dimension - i.e. your labels should be integers, not one-hot encoded vectors.