Reputation: 1417
I am running a neural network, whose input should be of size (128, 128, 3)
. I have a dataset of images of size (256, 256, 3)
So, I am resizing every image img
before inputting to neural network.
img.resize(128, 128, 3)
It is working well for some batches or some epochs.
But suddenly the program returns error due to resizing image as follows
ValueError: resize only works on single-segment arrays
I thought that there may be some issue with shape of images in my dataset, but the shapes of image are same through out my dataset i.e., (256, 256, 3)
. And I have no clue about this error.
If there is any issue with the resize
function, then how does it work for some images and pops-up error for some other? Am I wrong anywhere?
Upvotes: 0
Views: 2650
Reputation: 142
For images, resizing using PIL is one possible method.
import numpy as np
from PIL import Image
np.array(Image.fromarray(img.astype(np.uint8)).resize((256, 256))).astype('float32')
as explained at TypeError: Cannot handle this data type: (1, 1, 3), <f4
Upvotes: 1