I currently working on a machine learning project, and I implemented data augmentation by myself for some reason.
The type of image is
'PIL.JpegImagePlugin.JpegImageFile'
And I'd like to append my image to list called images.
#method "scale_augmentation" is self defined function. Return image.
f_processed = self.scale_augmentation(image = f)
#error occurs here
self.images.append(Image.fromarray(f_processed.convert('RGB'), dtype=np.float32) / 255.)
I'm stuck with this error for so long and I've gone through many stack overflow questions regarding to this error. Thanks in advance.
Scale_augmentation function looks like this
def scale_augmentation(image, scale_range=(256, 400), crop_size=224):
scale_size = np.random.randint(*scale_range)
image = imresize(image, (scale_size, scale_size))
image = random_crop(image, (crop_size, crop_size))
return image
Also error looks like this
--> 100 self.images.append(Image.fromarray(f_processed.convert('RGB'), dtype=np.float32) / 255.)
AttributeError: 'numpy.ndarray' object has no attribute 'convert'
numpy.ndarrayis not anImage. you probably want to callconverton theImageobject.type(f_processed).typechecks onf_processedorimagetill you find where you start to getndarrayinstead of the expectedImage. Since you haven't provided full working code, only you can add those debugging tests.