我試圖將本教程的專家部分應用於我自己的數據,但我一直遇到維度錯誤。這是導致錯誤的代碼。如何解決TensorFlow中的尺寸錯誤?
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
def max_pool_2x2(x):
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1], padding='SAME')
W_conv1 = weight_variable([1, 8, 1, 4])
b_conv1 = bias_variable([4])
x_image = tf.reshape(tf_in, [-1,2,8,1])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
h_pool1 = max_pool_2x2(h_conv1)
,然後當我嘗試運行此命令:
W_conv2 = weight_variable([1, 4, 4, 8])
b_conv2 = bias_variable([8])
h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
h_pool2 = max_pool_2x2(h_conv2)
我收到以下錯誤:
ValueError Traceback (most recent call last)
<ipython-input-41-7ab0d7765f8c> in <module>()
3
4 h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
----> 5 h_pool2 = max_pool_2x2(h_conv2)
ValueError: ('filter must not be larger than the input: ', 'Filter: [', Dimension(2), 'x', Dimension(2), '] ', 'Input: [', Dimension(1), 'x', Dimension(4), '] ')
只是爲了一些背景信息,我正在着手處理數據與一個CSV文件,其中每行包含10個功能和1個空列可以是1或0.我試圖得到的是空列中的概率列將等於1.
什麼是'tf_in'?我假設它是原始的1x8輸入。 – erickrf
'data = genfromtxt('cs-training.csv',delimiter =',')'。 'A = data.shape [1] -1'。 'tf_in = tf.placeholder(「float」,[None,A])'。 – NickTheInventor