import glob
from PIL import Image
marked = glob.iglob("D:/Users/username/Desktop/cells/Marked")
img = Image.open(marked)
img.show()
I am trying to create a neural network using an image dataset contained in the Folder marked. When I run the code I get the error:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PIL/Image.py", line 2547, in open
fp.seek(0)
AttributeError: 'generator' object has no attribute 'seek'
I do not understand what the error means, it seems to be misdirected?
To load the image, we simply import the image module from the pillow and call the Image. open(), passing the image filename. Instead of calling the Pillow module, we will call the PIL module as to make it backward compatible with an older module called Python Imaging Library (PIL).
You'll need to specify a wildcard at the end of your path and iterate:
images = []
for f in glob.iglob("D:/Users/username/Desktop/cells/Marked/*"):
images.append(np.asarray(Image.open(f)))
images = np.array(images)
See this answer, which uses PIL.Image and glob to find all images in the folder and load them into an array.
from PIL import Image
import glob
image_list = []
for filename in glob.glob('yourpath/*.gif'): #assuming gif
im=Image.open(filename)
image_list.append(im)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With