找不到 Keras TensorFlow 图像数据
Keras TensorFlow Image Data cannot be found
我正在尝试训练我的模型来读取一些 X 射线图像,我正在使用 Jupyter Notebook,我导入了库,定义了图像属性,准备了数据集,创建了神经网络模型,定义了回调...并管理了数据,但现在我在尝试训练模型时遇到了这个错误。
train_datagen = ImageDataGenerator(rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1
)
train_generator = train_datagen.flow_from_dataframe(train_df,
"C:/Users/lenovo/PneumoniaClassification/chest_xray/train",x_col='filename',y_col='category',
target_size=Image_Size,
class_mode='categorical',
batch_size=batch_size)
validation_datagen = ImageDataGenerator(rescale=1./255)
validation_generator = validation_datagen.flow_from_dataframe(
validate_df,
"C:/Users/lenovo/PneumoniaClassification/chest_xray/train",
x_col='filename',
y_col='category',
target_size=Image_Size,
class_mode='categorical',
batch_size=batch_size
)
test_datagen = ImageDataGenerator(rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1)
test_generator = train_datagen.flow_from_dataframe(train_df,
"C:/Users/lenovo/PneumoniaClassification/chest_xray/test",x_col='filename',y_col='category',
target_size=Image_Size,
class_mode='categorical',
batch_size=batch_size)
这是错误代码
Found 0 validated image filenames belonging to 0 classes.
Found 0 validated image filenames belonging to 0 classes.
Found 0 validated image filenames belonging to 0 classes.
C:\Users\lenovo\AppData\Roaming\Python\Python39\site-packages\keras_preprocessing\image\dataframe_iterator.py:279: UserWarning: Found 2 invalid image filename(s) in x_col="filename". These filename(s) will be ignored.
warnings.warn(
C:\Users\lenovo\AppData\Roaming\Python\Python39\site-packages\keras_preprocessing\image\dataframe_iterator.py:279: UserWarning: Found 1 invalid image filename(s) in x_col="filename". These filename(s) will be ignored.
warnings.warn(
C:\Users\lenovo\AppData\Roaming\Python\Python39\site-packages\keras_preprocessing\image\dataframe_iterator.py:279: UserWarning: Found 2 invalid image filename(s) in x_col="filename". These filename(s) will be ignored.
warnings.warn(
路径如下:
train 文件夹中有两个文件夹 NORMAL 和 PNEUMONIA?
如果是这样,那么您需要使用 flow_from_directory 而不是 flow_from_dataframe:
base_dir = "C:/Users/lenovo/PneumoniaClassification/chest_xray"
train_dir = os.path.join(base_dir, 'train')
test_dir = os.path.join(base_dir, 'test')
validation_dir = os.path.join(base_dir, 'val')
train_datagen = ImageDataGenerator(rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1
)
train_generator = train_datagen.flow_from_directory(
train_dir, # This is the source directory for training images
target_size=Image_Size, # All images will be resized
batch_size=BATCH_SIZE,
# Since we use binary_crossentropy loss, we need binary labels
class_mode='binary')
validation_datagen = ImageDataGenerator(rescale=1./255)
validation_generator = test_datagen.flow_from_directory(
validation_dir,
target_size=Image_Size,
batch_size=BATCH_SIZE,
class_mode='binary')
test_datagen = ImageDataGenerator(rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1)
test_generator = test_datagen.flow_from_directory(
test_dir,
target_size=Image_Size,
batch_size=BATCH_SIZE,
class_mode='binary')
我正在尝试训练我的模型来读取一些 X 射线图像,我正在使用 Jupyter Notebook,我导入了库,定义了图像属性,准备了数据集,创建了神经网络模型,定义了回调...并管理了数据,但现在我在尝试训练模型时遇到了这个错误。
train_datagen = ImageDataGenerator(rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1
)
train_generator = train_datagen.flow_from_dataframe(train_df,
"C:/Users/lenovo/PneumoniaClassification/chest_xray/train",x_col='filename',y_col='category',
target_size=Image_Size,
class_mode='categorical',
batch_size=batch_size)
validation_datagen = ImageDataGenerator(rescale=1./255)
validation_generator = validation_datagen.flow_from_dataframe(
validate_df,
"C:/Users/lenovo/PneumoniaClassification/chest_xray/train",
x_col='filename',
y_col='category',
target_size=Image_Size,
class_mode='categorical',
batch_size=batch_size
)
test_datagen = ImageDataGenerator(rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1)
test_generator = train_datagen.flow_from_dataframe(train_df,
"C:/Users/lenovo/PneumoniaClassification/chest_xray/test",x_col='filename',y_col='category',
target_size=Image_Size,
class_mode='categorical',
batch_size=batch_size)
这是错误代码
Found 0 validated image filenames belonging to 0 classes.
Found 0 validated image filenames belonging to 0 classes.
Found 0 validated image filenames belonging to 0 classes.
C:\Users\lenovo\AppData\Roaming\Python\Python39\site-packages\keras_preprocessing\image\dataframe_iterator.py:279: UserWarning: Found 2 invalid image filename(s) in x_col="filename". These filename(s) will be ignored.
warnings.warn(
C:\Users\lenovo\AppData\Roaming\Python\Python39\site-packages\keras_preprocessing\image\dataframe_iterator.py:279: UserWarning: Found 1 invalid image filename(s) in x_col="filename". These filename(s) will be ignored.
warnings.warn(
C:\Users\lenovo\AppData\Roaming\Python\Python39\site-packages\keras_preprocessing\image\dataframe_iterator.py:279: UserWarning: Found 2 invalid image filename(s) in x_col="filename". These filename(s) will be ignored.
warnings.warn(
路径如下:
train 文件夹中有两个文件夹 NORMAL 和 PNEUMONIA? 如果是这样,那么您需要使用 flow_from_directory 而不是 flow_from_dataframe:
base_dir = "C:/Users/lenovo/PneumoniaClassification/chest_xray"
train_dir = os.path.join(base_dir, 'train')
test_dir = os.path.join(base_dir, 'test')
validation_dir = os.path.join(base_dir, 'val')
train_datagen = ImageDataGenerator(rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1
)
train_generator = train_datagen.flow_from_directory(
train_dir, # This is the source directory for training images
target_size=Image_Size, # All images will be resized
batch_size=BATCH_SIZE,
# Since we use binary_crossentropy loss, we need binary labels
class_mode='binary')
validation_datagen = ImageDataGenerator(rescale=1./255)
validation_generator = test_datagen.flow_from_directory(
validation_dir,
target_size=Image_Size,
batch_size=BATCH_SIZE,
class_mode='binary')
test_datagen = ImageDataGenerator(rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1)
test_generator = test_datagen.flow_from_directory(
test_dir,
target_size=Image_Size,
batch_size=BATCH_SIZE,
class_mode='binary')