Closed brijml closed 7 years ago
I figured it out by using a placeholder in place of "img" in this line,
net = DeepLabResNetModel({'data': tf.expand_dims(img, dim=0)}, is_training=False, num_classes=args.num_classes)
to
img_ph = tf.placeholder(tf.float32, shape = [None, None, None, 3])
net = DeepLabResNetModel({'data': img_ph}, is_training=False, num_classes=args.num_classes)
and feeding in the batch of images
Thank You
Could you share any sample code showing how to feed the images?
Thanks
import cv2, os, numpy
import tensorflow as tf
#if you have stored the images in a directory, directory_path is the absolute path to the directory
imgs = []
for file_ in os.listdir(directory_path):
img = cv2.imread(os.path.join(directory_path,file_))
imgs.append(img)
#all the images must be of same size, you will have to resize if they are not of same size
#imgs is list of numpy ndarrays, you can convert this list to array so that now this array can be used as a tensor
imgs_array = numpy.array(img)
#You will have defined an op called 'pred'
#Now when you sess.run the op, you will use feed_dict to feed the imgs_array tensor
with tf.Session() as sess:
preds = sess.run(pred, feed_dict={imgs_ph:imgs_array})
Thanks, that helped a lot. I was using pillow and converting the loaded image to a numpy array. Using opencv made it work without a problem.
How to implement the complete code, thank you
How to implement the complete code, thank you @wycm2022 I wrote the code here: https://gist.github.com/davodogster/88794fea3f6800fd2150f7d436f06e34
How can one use the inference.py file for a batch a of multiple images?