1

I am trying to learn how to build a neural network to detect pedestrians in images. I downloaded the PETA dataset and I want to read the images into a Tensorflow dataset. I actually succeeded it by using this code:

filenames = glob.glob("C://PETA/3DPeS/archive/*.bmp")

dataset = tf.data.Dataset.from_tensor_slices((filenames))

def _parsefunc(filename):
    img_st = tf.read_file(filename)
    img_dec = tf.image.decode_bmp(img_st,channels=3)
    img = tf.cast(img_dec,tf.float32)

return img

dataset = dataset.map(_parsefunc)

iterator = dataset.make_one_shot_iterator()

But not all the images have the same resolutions and as long as I can see we need to specify a certain size to define our neural network layers.

So how can I resize the images to get a clean TensorFlow dataset?

Thanks.

harunuz
  • 135
  • 1
  • 2
  • 8

2 Answers2

2

In your _parsefunc you can do the resize of the input images to the size of your input neural network layer, using tf.image.resize_images().

def _parsefunc(filename):
   img_st = tf.read_file(filename)
   img_dec = tf.image.decode_bmp(img_st,channels=3)
   img = tf.cast(img_dec,tf.float32)
   img = tf.image.resize_images(img, [width, height])
Vijay Mariappan
  • 16,921
  • 3
  • 40
  • 59
1

Well, it is not enforced anywhere that your images should be of same size, but its better to have in such manner. If you are trying to fine-tune the models in the future, then it doesn't matter. Try to take a look, how to create Tfrecords for a new database and that would be most preferred way.

saikishor
  • 878
  • 3
  • 11
  • 21