I have about 1.5 GB of images that I need to process. The problem is that when I try loading them as np arrays I seem to use up all of my ram (8 GB).
Here is my method for loading images:
def load_image( infilename ) :
img = Image.open( infilename )
img.load()
data = np.asarray( img, dtype="int32" )
img.close()
del img
return data
I thought closing and deleting the img would help, but it doesn't. Can this have something to do with garbage collection?
Code to loop through all images in a list of file names:
for i in range(len(files)):
imgArray = imgs.load_image(files[i])
images.append(imgArray)
shapes.append(np.shape(imgArray))
Is there a better way?
(width, height)values per image, rather than the entire image arrays...