我一直在尝试建立一个能够对图像进行分类的神经网络模型。但是,这个持续不断的错误不断出现。谁能帮我这个忙吗?以下是代码和错误: Second Traceback third Traceback
x=tf.placeholder(tf.float32,shape=[None,img_size])
y=tf.placeholder(tf.float32,shape=[None,no_classes])
#keep_probable=tf.argmax(y,dimension=1)
keep_probable=tf.placeholder(tf.float32)
def conv2d(x,w,b,strides=1):
x=tf.nn.conv2d(x,w, strides=[1,strides,strides,1],padding='SAME')
x=tf.nn.bias_add(x,b)
return tf.nn.relu(x)
def maxpool2d(x,k=2):
return tf.nn.max_pool(x,ksize=[1,k,k,1],strides=[1,k,k,1],padding='SAME')
def conv_net(x,weights,biases,drop_out):
x=tf.reshape(x,shape=[-1,50,50,1])
conv1=conv2d(x,weights['wc1'],biases['bc1'])
conv1=maxpool2d(conv1,k=2)
conv2=conv2d(conv1,weights['wc2'],biases['bc2'])
conv2=maxpool2d(conv2,k=2)
fcl=tf.reshape(conv2,[-1,weights['wd1'].get_shape().as_list()[0]])
fcl=tf.add(tf.matmul(fcl,weights['wd1'])[][2],biases['bd1'])
fcl=tf.nn.relu(fcl)
# application of dropout
fcl.tf.nn.dropout(fcl,dropout)
# output of the class prediction
out=tf.add(tf.matmul(fcl,weights['out']),biases['out'])
return out
weights = {
'wc1': tf.Variable((tf.random_normal)([5,5,1,32])),
'wc2': tf.Variable((tf.random_normal)([5,5,32,64])),
'wd1': tf.Variable((tf.random_normal)([7*7*64,1024])),
'out': tf.Variable((tf.random_normal)([1024,no_classes]))
}
biases = {
'bc1': tf.Variable(tf.random_normal([32])),
'bc2': tf.Variable(tf.random_normal([64])),
'bd1': tf.Variable(tf.random_normal([1024])),
'out': tf.Variable(tf.random_normal([no_classes]))
}
# construction of a model
pred = conv_net(x,weights,biases,keep_probable)
# definition of the loss and optimizer
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred,labels =y))
optimiser = tf.train.AdadeltaOptimizer(learning_rate=LR).minimize(cost)
# Evaluating the model
correct_pred = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
accuracy=tf.reduce_mean(tf.cast(correct_pred,tf.float32))
以下是我得到的错误:
TypeError: Expected bool for argument 'transpose_a' not <tf.Variable 'Variable_6:0' shape=(1024,) dtype=float32_ref>.
答案 0 :(得分:0)
问题在您的fcl=tf.add(tf.matmul(fcl,weights['wd1'],biases['bd1']))
行中。您缺少括号。这样做:
fcl=tf.add(tf.matmul(fcl,weights['wd1']),biases['bd1'])