添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to load all the images before i can head towards my CNN model but i am getting this error.I don't know what is the problem. please help me out.

# Setting up the image pool
image_path = "C:\\Users\\New\\Desktop\\images"
imgs = os.listdir(image_path)
img_x = img_y = 50 # image size is constant
n_samples = np.size(imgs)
n_samples # 20778 originally
# Loading all images...
images = np.array([np.array(Image.open(image_path +  
imgs).convert("RGB")).flatten() for imgs in os.listdir(image_path)], 
order='F', dtype='uint8')
np.shape(images)

i got this error

FileNotFoundError Traceback (most recent call last) 1 # Loading all images... ----> 2 images = np.array([np.array(Image.open(image_path + imgs).convert("RGB")).flatten() for imgs in os.listdir(image_path)], order='F', dtype='uint8') 3 np.shape(images)

in (.0) 1 # Loading all images... ----> 2 images = np.array([np.array(Image.open(image_path + imgs).convert("RGB")).flatten() for imgs in os.listdir(image_path)], order='F', dtype='uint8') 3 np.shape(images)

~\Anaconda3\lib\site-packages\PIL\Image.py in open(fp, mode) 2608 if filename: -> 2609 fp = builtins.open(filename, "rb") 2610 exclusive_fp = True

FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\New\Desktop\imagesAlfa Romeo10882_small.jpg'

  • you used image_path + imgs, lets assuem in imgs you have the one image relative path, it will be still missing a "/" try please to use os.path.join to avoid it.

  • when you run the for loop it is redundant to run over os.listdir(image_path) as you already have it under imgs,

  • try the following, should work

    from PIL import Image
    image_path = "path to folder with images...."
    imgs = os.listdir(image_path) # create a list of all the files inside the fodler
    img_x = img_y = 50  # image size is constant
    n_samples = np.size(imgs)
    print(n_samples) 
    images = np.array([np.array(Image.open(os.path.join(image_path,im)).convert("RGB")).flatten() for im in imgs],
                          order='F', dtype='uint8')
    print(np.shape(images))
    

    my output is :

    (1000, 921600)

    good luck

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.