I'm new to Python and I'm trying to load a series of images as an array. All of the images are in the same folder.
Here's the code I'm using.
import os
from os import listdir
from matplotlib import image, pyplot
loaded_images = list()
for filename in listdir('UFO-120/train_val/lrd'):
# load image
lr_train_data = image.imread(filename, format='JPG')
# store loaded image
loaded_images.append(lr_img_data)
print('> loaded %s %s' % (filename, lr_train_data.shape))
Here's the entire error message.
FileNotFoundError Traceback (most recent call last)
<ipython-input-4-81fe8e3a7102> in <module>()
6 for filename in listdir('UFO-120/train_val/lrd'):
7 # load image
----> 8 lr_train_data = image.imread(filename, format='JPG')
9 # store loaded image
10 loaded_images.append(lr_img_data)
1 frames
/usr/local/lib/python3.6/dist-packages/matplotlib/image.py in imread(fname, format)
1462 raise ValueError('Only know how to handle PNG; with Pillow '
1463 'installed, Matplotlib can handle more images')
-> 1464 with Image.open(fname) as image:
1465 return pil_to_array(image)
1466 from matplotlib import _png
/usr/local/lib/python3.6/dist-packages/PIL/Image.py in open(fp, mode)
2807
2808 if filename:
-> 2809 fp = builtins.open(filename, "rb")
2810 exclusive_fp = True
2811
FileNotFoundError: [Errno 2] No such file or directory: 'set_o406.jpg'
The error seems to be telling me that all of the files need to have the .png file extension, but I thought using the matplotlib image.imread would resolve that. I also added the format='JPG' declaration but that didn't make a difference.
As to the File Not Found Error, 'set_o406.jpg' is a valid file name in the folder.
The folder does contain 1500 images and 'set_o406.jpg' is # 754/1500, is it possible that I'm exceeding the memory that can be loaded into a single array? If so, can you recommend a way to work around that?
I'd appreciate any help you're able to provide. Thank you.