Reputation: 21
I am facing an error while making a function in python error type 'JpegImageFile' object is not iterable'
please suggest how to solve this issue.
def image_processing(test_path, img_size=(331, 331, 3)):
test_filenames = [i for i in (test_path)]
images = np.zeros([img_size[0], img_size[1],3],dtype=np.uint8)
for ix, img_dir in enumerate(tqdm(test_filenames)):
img = load_img(img_dir, target_size=img_size)
images[ix]=img
del img
print('test image data:', images.shape)
return images
X = image_processing(image, img_size)
The full error
TypeError: 'JpegImageFile' object is not iterable
Traceback:
File "c:\programdata\anaconda3\lib\site-packages\streamlit\script_runner.py", line 324, in _run_script
exec(code, module.__dict__)
File "E:\Dog-120-Breeds\app_3.py", line 77, in <module>
X = image_processing(image, img_size)
File "E:\Dog-120-Breeds\app_3.py", line 50, in image_processing
test_filenames = [i for i in (test_path)]
Upvotes: 2
Views: 3496
Reputation: 341
I can't see what you've defined outside of the one function, but looking at your variable names it seems you're passing an image into the function as test_path
where you probably want to pass a path.
Also, if your intention with the line test_filenames = [i for i in (test_path)]
is to get the filenames of all files under the path, you might want to look at os.listdir() - your current approach will just iterate over the characters in the path.
Upvotes: 1