私は1次元入力を分類すべき畳み込みニューラルネットワーク(Tensorflow)を構築しています。ここで1D CNN for classification
は私のコードは、これまでのところです:私は上記のコードを実行すると、私は次のエラーを取得
import tensorflow as tf
n_outputs = 1
batch_size = 32
x = tf.placeholder(tf.float32, [batch_size, 10, 1])
filt = tf.zeros([3, 1, 1])
output = tf.nn.conv1d(x, filt, stride=2, padding="VALID")
y = tf.placeholder(tf.int32)
logits = tf.layers.dense(output, n_outputs)
xentropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y, logits=logits)
correct = tf.nn.in_top_k(logits, y, 1)
:エラーに基づいて
Traceback (most recent call last): File "minex.py", line 16, in correct = tf.nn.in_top_k(logits, y, 1) File "/home/jk/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 1449, in in_top_k targets=targets, k=k, name=name) File "/home/jk/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op op_def=op_def) File "/home/jk/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2329, in create_op set_shapes_for_outputs(ret) File "/home/jk/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1717, in set_shapes_for_outputs shapes = shape_func(op) File "/home/jk/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1667, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/home/jk/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn debug_python_shape_fn, require_shape_fn) File "/home/jk/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 676, in _call_cpp_shape_fn_impl raise ValueError(err.message) ValueError: Shape must be rank 2 but is rank 3 for 'InTopK' (op: 'InTopK') with input shapes: [32,4,1], ?.
を、私の問題がでているようですしかし、なぜそれが起こっているのか、それをどう修正するのかはわかりません。
もっと一般的な解決策である[tf.reshape](https://www.tensorflow.org/api_docs/python/tf/reshape)について言及しているかもしれませんが、この場合、tf.squeezeは理解しやすくなります。この[tf.expand_dims](https://www.tensorflow.org/api_docs/python/tf/expand_dims)の隣には、tf.squeezeよりも多かれ少なかれ逆のことがあります。 –