I have simple code:
data_dir_str = "./photo/pults/samsung_small"
data_dir = pathlib.Path(data_dir_str)
image_count = len(list(data_dir.glob('*.*')))
print('images in directory: ' + str(image_count)) # 12 files in directory
sams_pults = list(data_dir.glob('*.jpg'))
img = PIL.Image.open(str(sams_pults[0]))
img_width, img_height = img.size
#img.show() # This works well - shows image
batch_size = 10
train_ds = tf.keras.utils.image_dataset_from_directory(
data_dir_str, #data_dir,
validation_split=0.2,
subset="training",
#seed=123,
image_size=(img_height, img_width),
batch_size=batch_size
)
All images are in jpg-format. I can see a picture when use img.show
. But image_dataset_from_directory
gives me the error: "No images found in directory {directory}. Allowed formats: {ALLOWLIST_FORMATS}"
I don't understand what's wrong.
I have found the solution:
./photo/pults/samsung_small
-> ./photo/pults
The path needs to be set not as a dir where images are placed but one level above. Because the dir name is used for classification.
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.