简体   繁体   中英

Load in images to jupyter notebook

I am getting an error loading in images from folders. I have loaded in the following:

base_path = '/Users/rayday/Desktop/COMP309_2020_Project/'
train_dir = '/Users/rayday/Desktop/COMP309_2020_Project/Train_data/'
test_dir ='/Users/rayday/Desktop/COMP309_2020_Project/ProjectTemplate_python3.7/data/test/'

When I run the below chunk of code

print('Training Data')
for direc in os.listdir(train_dir):
    print(direc, ':',len(os.listdir(train_dir+direc)))

I get an error saying 'Not a directory'.

A easy way to do this is with the glob module, for example:

import glob

image_paths = glob.glob('images/*.jpg')

for image_path in image_paths:
    # Load image
    original_image = Image.open(image_path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM