#python #multidimensional-array #error-handling #tensorflow
#python #многомерный массив #обработка ошибок #тензорный поток
Вопрос:
я изучаю глубокое обучение. Я использую библиотеку TensorFlow с Jupyter ipython. У меня проблема,
train_subset = 10000
num_labels = 5
data_size = 42
graph = tf.Graph()
with graph.as_default():
# Input data.
# Load the training, validation and test data into constants that are
# attached to the graph.
tf_train_dataset = tf.constant(train_set[:train_subset, :])
tf_train_labels = tf.constant(train_labels[:train_subset])
tf_valid_dataset = tf.constant(valid_set)
tf_test_dataset = tf.constant(test_set)
beta_regul = tf.placeholder(tf.float32)
# Variables.
# These are the parameters that we are going to be training. The weight
# matrix will be initialized using random values following a (truncated)
# normal distribution. The biases get initialized to zero.
weights = tf.Variable(
tf.truncated_normal([data_size, num_labels]))
biases = tf.Variable(tf.zeros([num_labels]))
# Training computation.
# We multiply the inputs with the weight matrix, and add biases. We compute
# the softmax and cross-entropy (it's one operation in TensorFlow, because
# it's very common, and it can be optimized). We take the average of this
# cross-entropy across all training examples: that's our loss.
logits = tf.matmul(tf_train_dataset, weights) biases
loss = tf.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits(logits, tf_train_labels)) beta_regul * tf.nn.l2_loss(weights)
# Optimizer.
# We are going to find the minimum of this loss using gradient descent.
optimizer = tf.train.GradientDescentOptimizer(0.5).minimize(loss)
# Predictions for the training, validation, and test data.
# These are not part of training, but merely here so that we can report
# accuracy figures as we train.
train_prediction = tf.nn.softmax(logits)
valid_prediction = tf.nn.softmax(
tf.matmul(tf_valid_dataset, weights) biases)
test_prediction = tf.nn.softmax(tf.matmul(tf_test_dataset, weights) biases)
Ошибка отображается в следующих строках
Ошибка значения: размерность 0 в обеих формах должна быть равной, но равна 10000 и 1
Комментарии:
1. train_set[240000][42] test_set[30000][42] valid_set[30000][42]
2. Можете ли вы включить полное сообщение об ошибке, включая трассировку стека Python? Какие строки кода были вовлечены в ошибку?