I have such code, which should train my neural network. But i can't understand why i have an error when I try to start test.
with graph.as_default():
images_ph = tf.placeholder(tf.float32, [25432, 32, 32, 3])
labels_ph = tf.placeholder(tf.int32, [25432])
images_flat = tf.contrib.layers.flatten(images_ph)
logits = tf.contrib.layers.fully_connected(images_flat, 68, tf.nn.relu)
predicted_labels = tf.argmax(logits, 1)
loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels_ph))
train = tf.train.AdamOptimizer(learning_rate=0.001, epsilon=0.00000001).minimize(loss)
all_saver = tf.train.Saver()
init = tf.global_variables_initializer()
session = tf.Session(graph=graph)
_ = session.run([init])
steps = 401
for i in range(steps):
_, loss_value = session.run([train, loss], feed_dict={images_ph: images_a, labels_ph: labels_a})
if i % 10 == 0:
print("Loss: ", loss_value)
all_saver.save(session, output_graph, global_step=steps)
# Pick 10 random images
sample_indexes = random.sample(range(len(images32)), 10)
sample_images = [images32[i] for i in sample_indexes]
sample_labels = [labels[i] for i in sample_indexes]
predicted = session.run([predicted_labels], feed_dict={images_ph: sample_images})[0]
When you try to start, an error occurs after the network training phase. Namely, at the testing stage. What could be the problem?
Error:
ValueError: Cannot feed value of shape (10, 32, 32, 3) for Tensor 'Placeholder:0', which has shape '(25432, 32, 32, 3)
'
Line:
predicted = session.run([predicted_labels], feed_dict={images_ph: sample_images})[0]