我试图获得训练集的预测,但我总是得到每张图像相同的结果。有人可以帮帮我吗?
这就是我定义网络的方式:
x = tf.placeholder(tf.float32, shape=[None, image_size_h, image_size_v, num_channels])
y_ = tf.placeholder(tf.float32, shape=[None, num_classes])
keep_prob = tf.placeholder(tf.float32)
def conv_net(x1, weights, biases):
# First Convolution Layer
conv1 = conv2d_pool(x1, weights['wc1'], biases['bc1'], 'conv1')
#print(conv1.get_shape())
# Second Convolution Layer
conv2 = conv2d(conv1, weights['wc2'], biases['bc2'], 'conv2')
conv3 = conv2d(conv2, weights['wc3'], biases['bc3'], 'conv3')
conv4 = conv2d(conv3, weights['wc4'], biases['bc4'],'conv4')
conv5 = conv2d(conv4, weights['wc5'], biases['bc5'],'conv5')
conv6 = conv2d(conv5, weights['wc6'], biases['bc6'],'conv6')
# Fully connected layer
fc1 = fullycon(conv6, weights['wd1'], biases['bd1'], 'fc1')
# Dropout
fc1_drop = tf.nn.dropout(fc1, keep_prob)
fc2 = fullytanh(fc1_drop, weights['wd2'], biases['bd2'], 'fc2')
out = tf.add(tf.matmul(fc2, weights['out']), biases['bout'])
return out
pred = conv_net(x, weights, biases)
prediyo = tf.argmax(tf.nn.softmax(pred), axis=1)
# Loss and optimizer
correct_prediction = tf.equal(tf.argmax(y_,axis=1), tf.argmax(pred,axis=1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
optimizer = tf.train.AdamOptimizer(learning_rate=lr).minimize(cost)
虽然我做了预测:
result_boxes_n = normalise_images(result_boxes)
for n in range (0,result_boxes.shape[0]):
predicted = prediyo.eval(feed_dict={x:np.reshape(result_boxes_n[n,:,:,:],(1,9,8,3)), keep_prob: 1})
print(predicted)
尽管训练精度高于90%,但预测的输出始终是同一级别。但是,如果我这样做:
prediyo.eval(feed_dict={x:result_boxes_n, keep_prob: 1})
它有效,但当我尝试做个别预测时没有。
提前致谢