0
我目前正在建立一個CNN來區分一個爛蘋果和一個普通的蘋果。我覺得如果我可以用CNG提供RGB圖像,這將是非常有益的。但是,我需要更改以下網絡的具體內容?如何培養CNN的RGB圖像
x = tf.placeholder('float', [None, 784])
#y = tf.placeholder(tf.float32, shape=(), name="init")
y = tf.placeholder('int32')
keep_rate = 0.8
keep_prob = tf.placeholder(tf.float32)
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1,1,1,1], padding='SAME')
def maxpool2d(x):
# size of window movement of window
return tf.nn.max_pool(x, ksize=[1,2,2,1], strides=[1,2,2,1], padding='SAME')
def convolutional_neural_network(x):
weights = {'W_conv1':tf.Variable(tf.random_normal([5,5,1,32])),
'W_conv2':tf.Variable(tf.random_normal([5,5,32,64])),
'W_fc':tf.Variable(tf.random_normal([7*7*64,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, 28, 28, 1])
print("test")
print(x)
conv1 = tf.nn.relu(conv2d(x, weights['W_conv1']) + biases['b_conv1'])
conv1 = maxpool2d(conv1)
conv2 = tf.nn.relu(conv2d(conv1, weights['W_conv2']) + biases['b_conv2'])
conv2 = maxpool2d(conv2)
fc = tf.reshape(conv2,[-1, 7*7*64])
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
我試圖改變某些值,但是我不斷得到一個接一個的錯誤。該網絡目前旨在拍攝28乘28通道1灰度圖像。
對不起,我不小心點擊了下投票按鈕。這不會讓我撤消投票 –
也應該我的maxpool函數中的步幅和k尺寸的第四個值更改爲3,因爲現在顏色通道值是三? –
阿哈如果你編輯你的回覆,我可以撤消倒票 –