【发布时间】:2023-03-10 15:21:01
【问题描述】:
我正在使用卷积神经网络对 3 个标签中的图像进行分类。我做了所有的训练和测试,得到了 60% 的准确率。然后,我保存了这个模型,我想加载一个图像并将其分类到其中一个标签中。我正在使用的代码:
X_new = process_data() # That's my input image after some processing
pred = convolutional_neural_network(x) # That's my CNN
with tf.Session() as sess:
# Here I restore the trained model
saver = tf.train.import_meta_graph('modelo.meta')
saver.restore(sess, 'modelo')
print('Model loaded')
sess.run(tf.initialize_all_variables())
# Here I'm trying to predict the label of my image
c = sess.run(pred, feed_dict={x: X_new})
print(c)
当我打印 c 时,它会返回如下内容:
[[ 1.5495030e+07 -2.3345528e+08 -1.5847101e+08]]
但我不知道这意味着什么以及我应该如何处理它。 无论如何,我想做的是获取图像属于某个标签的百分比。如果有人可以帮助我,我将不胜感激!我是 tensorflow 新手,遇到了一些困难。
非常感谢!
编辑:
卷积神经网络方法:
def convolutional_neural_network(x):
weights = {'W_conv1': tf.Variable(tf.random_normal([3, 3, 3, 1, 32])),
'W_conv2': tf.Variable(tf.random_normal([3, 3, 3, 32, 64])),
'W_fc': tf.Variable(tf.random_normal([54080, 1024])),
'out': tf.Variable(tf.random_normal([1024, n_classes]))}
biases = {'b_conv1': tf.Variable(tf.random_normal([32])),
'b_conv2': tf.Variable(tf.random_normal([64])),
'b_fc': tf.Variable(tf.random_normal([1024])),
'out': tf.Variable(tf.random_normal([n_classes]))}
x = tf.reshape(x, shape=[-1, IMG_PX_SIZE, IMG_PX_SIZE, HM_SLICES, 1])
conv1 = tf.nn.relu(conv3d(x, weights['W_conv1']) + biases['b_conv1'])
conv1 = maxpool3d(conv1)
conv2 = tf.nn.relu(conv3d(conv1, weights['W_conv2']) + biases['b_conv2'])
conv2 = maxpool3d(conv2)
fc = tf.reshape(conv2, [-1, 54080])
fc = tf.nn.relu(tf.matmul(fc, weights['W_fc']) + biases['b_fc'])
fc = tf.nn.dropout(fc, keep_rate)
output = tf.matmul(fc, weights['out']) + biases['out']
return output
【问题讨论】:
-
这个问题的答案很大程度上取决于convolutional_neural_network()中的内容
-
您好!感谢帮助,我添加了我的卷积网络的代码!
标签: python tensorflow deep-learning classification conv-neural-network