我正在使用Tensorflow构建CNN模型。以下是模型的架构
neckline_inputs_ = tf.placeholder(tf.float32, shape=[None, codes.shape[1]], name='neckline_inputs')
neckline_labels_ = tf.placeholder(tf.int64, shape=[None, label_vecs.shape[1]])
# TODO: Classifier layers and operations
neckline_layer = tf.contrib.layers.fully_connected(neckline_inputs_, 128)
neckline_logits = tf.contrib.layers.fully_connected(neckline_layer, label_vecs.shape[1], activation_fn=None)# output layer logits
neckline_cross_entropy = tf.nn.softmax_cross_entropy_with_logits(labels=neckline_labels_, logits=neckline_logits)# cross entropy loss
neckline_cost = tf.reduce_mean(neckline_cross_entropy)
neckline_optimizer = tf.train.AdamOptimizer().minimize(neckline_cost)# training optimizer
# Operations for validation/test accuracy
neckline_predicted = tf.nn.softmax(neckline_logits, name='neckline_prediction')
neckline_correct_pred = tf.equal(tf.argmax(neckline_predicted, 1), tf.argmax(neckline_labels_, 1))
neckline_accuracy = tf.reduce_mean(tf.cast(neckline_correct_pred, tf.float32))
我正在使用检查点保存上述模型
saver.save(sess, 'checkpoints/Neckline/neckline_ckpt')
我已在同一笔记本中还原了检查点,并将测试图像传递给了模型。它已经预测
saver = tf.train.Saver()
with tf.Session() as sess:
saver.restore(sess, 'checkpoints/Neckline/neckline_ckpt')
test = lb.classes_[np.argmax(sess.run(neckline_predicted, feed_dict={neckline_inputs_:code}), axis=1)]
print("Test accuracy {}".format(test))
它已经预测了Turtlenecks
虽然我使用以下代码将上述模型恢复到其他笔记本中。
with tf.Session() as sess_sleeve:
sleeve_saver = tf.train.import_meta_graph('checkpoints/Neckline/neckline_ckpt.meta')
sleeve_saver.restore(sess_sleeve, "checkpoints/Neckline/neckline_ckpt")
sleeve_graph = tf.get_default_graph()
inputs = sleeve_graph.get_tensor_by_name("neckline_inputs:0")
pred = sleeve_graph.get_tensor_by_name("neckline_prediction:0")
print(sess_sleeve.run(pred, feed_dict={inputs:code}))
print(neck_lb.classes_)
print(neck_lb.classes_[np.argmax(sess_sleeve.run(pred, feed_dict={inputs:code}), axis=1)])
我已经传递了与之前传递的图像相同的图像,它预测的结果是不同的。它已打印SquareNeck
我做错了吗