keras imagedatagenerator flow_from_dataframe:找到0个已验证的图像文件名属于0类

发布于 2025-01-24 16:14:15 字数 1548 浏览 0 评论 0原文

我正在处理存储为.npy文件的3D图像数据(128,128,128)。当我尝试使用keras imagedatagenerator时,它会引发以下错误:

找到0个已验证的属于0 class的图像文件名

我的代码如下:

processed_data =  r'C:/Users/dush/Desktop/Project/preprocessed'


from tensorflow.keras.preprocessing.image import ImageDataGenerator

img_size = 64
batch_size = 32

data_gen = ImageDataGenerator(horizontal_flip = True,
                              validation_split=0.2,
                               fill_mode = "nearest",
                               zoom_range = 0.3,
                               width_shift_range = 0.1,
                               height_shift_range = 0.1,
                               rotation_range = 30)


train_gen = data_gen.flow_from_dataframe(
        dataframe = train,
        directory = processed_data, 
        x_col = 'id',
        y_col = 'category',  
        target_size=(img_size, img_size, img_size),
        batch_size = batch_size,
        class_mode="binary",
        #validate_filenames=False,
        subset='training', seed = 23) #image_generator.flow_from_dataframe

valid_gen = data_gen.flow_from_dataframe(
    dataframe = train,
    directory = processed_data, 
    x_col = 'id',
    y_col = 'category',
    target_size=(img_size, img_size, img_size),
    #validate_filenames=False,
    batch_size=batch_size,
    class_mode="binary",
    subset='validation', shuffle=False, seed=23) 

如果我设置validate_filenames = false,则标识文件名但在拟合模型时会出现错误。我在做什么错?

I am working on 3D image data stored as .npy files with shape (128,128,128). When I try to use Keras ImageDataGenerator it throws the following error:

Found 0 validated image filenames belonging to 0 classes.

My code is as follows:

processed_data =  r'C:/Users/dush/Desktop/Project/preprocessed'


from tensorflow.keras.preprocessing.image import ImageDataGenerator

img_size = 64
batch_size = 32

data_gen = ImageDataGenerator(horizontal_flip = True,
                              validation_split=0.2,
                               fill_mode = "nearest",
                               zoom_range = 0.3,
                               width_shift_range = 0.1,
                               height_shift_range = 0.1,
                               rotation_range = 30)


train_gen = data_gen.flow_from_dataframe(
        dataframe = train,
        directory = processed_data, 
        x_col = 'id',
        y_col = 'category',  
        target_size=(img_size, img_size, img_size),
        batch_size = batch_size,
        class_mode="binary",
        #validate_filenames=False,
        subset='training', seed = 23) #image_generator.flow_from_dataframe

valid_gen = data_gen.flow_from_dataframe(
    dataframe = train,
    directory = processed_data, 
    x_col = 'id',
    y_col = 'category',
    target_size=(img_size, img_size, img_size),
    #validate_filenames=False,
    batch_size=batch_size,
    class_mode="binary",
    subset='validation', shuffle=False, seed=23) 

If I set validate_filenames=False, then it identifies the filenames but get an error when fitting the model. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文