【问题标题】:How to convert image files to tensor如何将图像文件转换为张量
【发布时间】:2021-05-25 07:56:24
【问题描述】:

我正在尝试将 NIH 胸部 X 射线(kaggle 中提供的数据集)图像转换为适合输入 Keras 模型的张量格式。

datagen=ImageDataGenerator(

)

datagen.fit('E:/Trial chest x-ray dataset/train resized (224,224)')

我尝试了上面提到的代码,但它说- 无法将字符串转换为浮点数:'E:/Trial chest X-ray dataset/train resized (224,224)'

然后我尝试了 flow_from_directory

from keras.preprocessing.image import ImageDataGenerator

train_datagen=ImageDataGenerator(rescale=1./255)
valid_datagen=ImageDataGenerator(rescale=1./255)

train_generator=train_datagen.flow_from_directory(
        train_images,
        target_size=(224,224),
        batch_size=26,
        class_mode='categorical'
)

validation_generator=valid_datagen.flow_from_directory(
        validation_images,
        target_size=(224,224),
        batch_size=26,
        class_mode='categorical'
)

但它是在说- 找到属于 0 个类别的 0 个图像。 找到属于 0 个类别的 0 张图片。

谁能告诉我如何将图像转换为适合 Keras 模型的格式?

【问题讨论】:

    标签: python tensorflow tensor


    【解决方案1】:

    这些文件夹是否已经创建?

    • train_images
    • validation_images...

    如果您还没有,请检查: https://www.tensorflow.org/hub/tutorials/tf2_image_retraining

    【讨论】:

      猜你喜欢
      • 2018-04-27
      • 2018-12-14
      • 2020-08-28
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2021-12-12
      相关资源
      最近更新 更多