【发布时间】:2019-07-22 13:14:41
【问题描述】:
这是我得到的错误:InvalidArgumentError(参见上面的回溯):logits 和 labels 必须具有相同的第一维,得到 logits 形状 [30,5] 和标签形状 [50]
我使用的批量大小为 50。我的分类问题的输出数量为 5。
我不知道 logits 形状中的 30 是从哪里来的。这是我的架构:
with tf.name_scope("pool3"):
pool3 = tf.nn.max_pool(conv2, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="VALID")
pool3_flat = tf.reshape(pool3, shape=[-1, 24000]) # must be a multiple of the input
pool3_flat_drop = tf.layers.dropout(pool3_flat, conv2_dropout_rate, training=training)
with tf.name_scope("fc1"):
flattened = tf.layers.flatten(pool3_flat_drop)
fc1 = tf.layers.dense(flattened , n_fc1, activation=tf.nn.relu, name="fc1")
fc1_drop = tf.layers.dropout(fc1, fc1_dropout_rate, training=training)
with tf.name_scope("output"):
# n_outputs = number of possible classes
logits = tf.layers.dense(fc1_drop, n_outputs, name="output")
Y_proba = tf.nn.softmax(logits, name="Y_proba")
with tf.name_scope("train"):
xentropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=y)
这也是我声明占位符的方式
with tf.name_scope('inputs'):
X = tf.placeholder(tf.float32, shape=[None, n_inputs], name='X')
X_reshaped = tf.reshape(X, shape=[-1, height, width, channels]) # make applicable to convolutional
y = tf.placeholder(tf.int32, shape=[None], name='y')
training = tf.placeholder_with_default(False, shape=[], name='training')
【问题讨论】:
标签: python tensorflow machine-learning