當我在tensorflow初學者,我用它在圖像上實現CNN,當我使用palceholder與feed_dir它給我的錯誤說Tensorflow錯誤使用佔位符
必須養活一個值佔位符
Grey_images = []
def Read_images():
for filename in glob.glob(r'Path*.jpg'):
img = Image.open(filename)
img = img.convert('L') # convert to gray scale
img = np.asanyarray(img)
img_shape = img.shape
img_reshaped = img.reshape(224,224,1 channels)
Grey_images.append(img_reshaped)#[#imgs,224,224,1]
Read_images()
img = tf.placeholder(dtype=tf.float32,shape=[None,224,224,1])
def RunAll():
layer = Layer(img,1,3,3,64,2,'Relu')
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
Prediction = sess.run(RunAll(),feed_dict={img:Grey_images})
這是類層
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(inp, W ,Stride):
return tf.nn.conv2d(inp, W, strides=[1, Stride ,Stride, 1], padding='SAME')
class Layer:
def __init__(self, inp,inp_channels_num,filter_width_size,filter_height_size,outp_channels_num,stride,activation_func):
sess = tf.Session()
self.W_conv = weight_variable([filter_width_size, filter_height_size, inp_channels_num, outp_channels_num])
self.b_conv = bias_variable([outp_channels_num])
if (activation_func=='Sigmoid'):
self.h_conv = tf.nn.sigmoid(Conv2d(inp, self.W_conv, stride) + self.b_conv)
else:
self.h_conv = tf.nn.relu(Conv2d(inp, self.W_conv, stride) + self.b_conv)
sess.run(tf.global_variables_initializer())
self.h_conv = sess.run(self.h_conv)
sess.close()
它給了我這個行的錯誤,但我使用feed_dir在sess.run(Runall())所以我錯過了什麼?
self.h_conv = sess.run(self.h_conv)
我在帖子的第一部分提到了錯誤'您必須爲佔位符提供一個值' –
檢查更新,希望它可以幫助 – Raady
我更新它並且它給了我相同的錯誤 –