我将图像分为train瓦尔和test文件夹,用于keras图像分类CNN。然而,train_datagen.flow_from_directory没有拾取任何图像。它说:找到了属于21个类的0个图像。我检查了目录,它们看起来很好。“”
import splitfolders
splitfolders.ratio('imagetype', output="output", seed=1337, ratio=(.8, 0.1,0.1))
import tensorflow as tf
from tensorflow import keras
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import categorical_crossentropy
from tensorflow.keras.preprocessing.image import ImageDataGenerator
train_path = "/home/ubuntu/imageTrain_dobby/SKJEWELLERY/BC4U/google_version/v1.1/lingyau_lee/output/train/"
val_path = "/home/ubuntu/imageTrain_dobby/SKJEWELLERY/BC4U/google_version/v1.1/lingyau_lee/output/val/"
test_path = "/home/ubuntu/imageTrain_dobby/SKJEWELLERY/BC4U/google_version/v1.1/lingyau_lee/output/test/"
img_width, img_height = 225,225 #1000, 1143
batch_size = 10
train_datagen = ImageDataGenerator(
rescale=1. / 255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1. / 255)
train_generator = train_datagen.flow_from_directory(
train_path,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode="categorical")
validation_generator = test_datagen.flow_from_directory(
val_path,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode="categorical")
'''
1条答案
按热度按时间jchrr9hc1#
路径应指向包含类的文件夹,每个类应有1个文件夹。