【问题标题】:ImageDataGenerator giving (almost) invisible imagesImageDataGenerator 提供(几乎)不可见的图像
【发布时间】:2021-07-27 16:37:06
【问题描述】:

我正在制作一个神经网络架构来预测图像是建筑物、森林、冰川、山脉、海洋还是街道。 Link 到数据集。

我正在使用tf.keras.preprocessing.image.ImageDataGenerator() 来加载和预处理我的数据。目录如下所示:

Dataset Directory

该目录包含大小为 150x150 的图像,如下所示:

Photo from class 'Building'

代码:

train_batch = tf.keras.preprocessing.image.ImageDataGenerator().flow_from_directory(directory=train_path, color_mode='rgb')
test_batch = tf.keras.preprocessing.image.ImageDataGenerator().flow_from_directory(directory=test_path)

>>> Found 14034 images belonging to 6 classes.
    Found 3000 images belonging to 6 classes.

img, labels = next(train_batch)
label_first_10 = labels[:10]
img_first_10 = img[:10]
class_name = ['buildings', 'forest', 'glacier', 'mountain', 'sea', 'street']

def plotImages(images_arr):
    fig, axes = plt.subplots(1, 10, figsize=(20,20))
    axes = axes.flatten()
    for img, ax in zip(images_arr, axes):
        ax.imshow(img)
        ax.axis('off')
    plt.tight_layout()
    plt.show()

>>>

Images after pre-processing

您可以看到我们几乎看不见的图像,甚至我都无法确定它来自哪个班级!所以,我不确定模型是否能够在这些类型的图像上进行训练。 任何人都可以设置其他一些超参数设置,以便我的图像可见并且可以被人眼识别。

【问题讨论】:

  • 试试ax.imshow(img / 255.0)
  • 感谢@Frightera,它成功了!但除以 255.0 时,它有何变化?

标签: python tensorflow image-processing keras deep-learning


【解决方案1】:

如果您在imshow 的参数中使用浮点值,它将假定值的范围是[0,1],并且该范围之外的任何值都会被剪裁。

因此你应该使用plt.imshow(img / 255)

如果您改为使用整数类型,它将假定范围为[0,255],请参阅docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多