1

I'm new to neural networks, and have been practicing image preprocessing. I am trying to resize images that are in the form of numpy arrays, and this is my current method:

# using tensorflow, resize the image
im = tf.image.resize(img_as_array, [299, 299])

# then use .eval() which returns a numpy array in the size I want
im_arr = im.eval(session=tf.compat.v1.Session())

Is there a better way to do this?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
sine_nomine
  • 109
  • 1
  • 1
  • 7

1 Answers1

1

To avoid having to convert between tf.tensor and np.ndarray tensor data types, you can use skimage (scikit-image) to resize the image directly on np.ndarray objects using the following code segment:

import skimage.transform

kwargs = dict(output_shape=self._size, mode='edge', order=1, preserve_range=True)
im = skimage.transform.resize(im, **kwargs).astype(im.dtype)

To install skimage, follow the installation instructions here: https://pypi.org/project/scikit-image/. Hope this helps!

Ryan Sander
  • 419
  • 3
  • 6