Reputation: 231
I'm beginner in tensorflow and i use it in implementing CNN on images and when i use palceholder with feed_dir it gives me error say
You must Feed a value for placeholder
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})
And this is class layer
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()
It gives me the error in this line however i use feed_dir in sess.run(Runall()) so what am i missing ?
self.h_conv = sess.run(self.h_conv)
Upvotes: 0
Views: 166
Reputation: 5206
The line where you run self.h_conv
also needs a feed_dict
provided.
Upvotes: 1
Reputation: 1726
your whole program run on the same line, you haven't mentioned what the error is ?
in function Read_images() you created have no return any value, so last line in function you should add
return Grey_images
and you are not saving the values after you read images.
in the program line Read_lines()
change to Grey_images = Read_lines()
Upvotes: 0