我刚刚训练了一个类似这样的模型:
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
num_examples = len(X_train)
print("W00T IT IS TRAINING ")
print()
for i in range(EPOCHS):
X_train, y_train = shuffle(X_train, y_train)
for offset in range(0, num_examples, BATCH_SIZE):
end = offset + BATCH_SIZE
batch_x, batch_y = X_train[offset:end], y_train[offset:end]
sess.run(training_operation, feed_dict={x: batch_x, y: batch_y})
validation_accuracy = evaluate(X_validation, y_validation)
print("EPOCH {} ...".format(i+1))
print("Validation Accuracy = {:.3f}".format(validation_accuracy))
print()
saver.save(sess, 'LeNet')
print("Model saved")
现在我已经加载了这样的一张图片:img1 = img.imread('./images_32x32/test_1.png')
现在我唯一想做的事情就是基于 img1
进行预测。
我该怎么做呢?
更新
加入我的 softmax 函数:
logits = LeNet(x)
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits, one_hot_y)
loss_operation = tf.reduce_mean(cross_entropy)
optimizer = tf.train.AdamOptimizer(learning_rate = rate)
training_operation = optimizer.minimize(loss_operation)
correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(one_hot_y, 1))
accuracy_operation = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
saver = tf.train.Saver()
x = tf.placeholder(tf.float32, (None, 32, 32, 3))
和y = tf.placeholder(tf.int32, (None))
。我不确定在这种情况下pred
会是什么。 - Bob van Luijtcorrect_prediction
吗?试图完全理解这最后一部分。我在softmax方面缺少一些东西... - Bob van Luijt