'TypeError: int() argument must be a string, a bytes-like object or a number, not 'Image'
I have a folder with images, I read all the images and resize them from 300x300 to 96x96 with this code:
from PIL import Image
import os
size = (96,96)
list_of_images = []
for filename in os.listdir(path):
image_directory = path+ '\\' +str(filename)
print(image_directory)
image = Image.open(image_directory)
image = image.resize(size)
list_of_images.append(image)
The list_of_images is a list of images (e.g [Image,Image,Image]) instead of arrays.
The problem occurs when I am trying to split the list and then put it together:
faults = list_of_images[0:700]
normal = list_of_images[1115:1800]
fault_label = Labels[0:700]
normal_label = Labels[1115:1800]
train_images = np.concatenate((faults, normal), axis = 0)
train_labels = np.concatenate((fault_label,normal_label), axis = 0)
When I am trying to concatenate I am getting this error:
train_images = np.concatenate((faults, normal), axis = 0)
File "<__array_function__ internals>", line 5, in concatenate
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Image'
Does anyone have any idea how to fix this?
Thank you.
edit
adapted from the unreadable comment
mgs1 = []
for i in range(len(names)):
img_byte_arr = io.BytesIO()
list_of_images[i].save(img_byte_arr, format='PNG')
img_byte_arr = img_byte_arr.getvalue()
imgs1.append(img_byte_arr)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
