【问题标题】:Converting and manipulation tf data image dataset straight from a folder直接从文件夹转换和操作 tf 数据图像数据集
【发布时间】:2022-06-22 21:18:21
【问题描述】:

我正在尝试从本地文件夹加载数据集并将其用作 tf 数据集。文件夹结构为:

   ../dataset/
      class_0/
      class_1/

其中 0 类子文件夹包含所有 0 类和 1 类所有 1 类图像。
为了实现这一点,我的代码是:

images = image_dataset_from_directory('../dataset/',
                                             shuffle=True,
                                             batch_size=32,
                                             image_size=(1080,1920))

所有图片的大小为(1080,1920,3)(1920,1080,3)

我正在尝试使用以下方式显示图像:

for image, labels in images.take(1):

      img = image[0].numpy() # take first image of batch
      print(img.shape)
      img = Image.fromarray(img, 'RGB')
      img.save('my.png')
      img.show()

打印图像形状=(1080, 1920, 3)

但是,PIL 显示的图像失真,看起来像是随机噪声。

知道我做错了什么吗?

【问题讨论】:

    标签: image tensorflow tensorflow2.0 tensorflow-datasets


    【解决方案1】:

    问题似乎在于 Pillow 的浮点数

    在你的转换函数中,你有img = Image.fromarray(img, 'RGB')

    将其更改为 img = Image.fromarray(img.astype('uint8'), 'RGB') 应该可以解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-03
      • 2019-05-16
      • 1970-01-01
      • 2021-10-04
      相关资源
      最近更新 更多