【问题标题】:Load image dataset from directory in place of MNIST dataset from tf.load从目录加载图像数据集,而不是从 tf.load 加载 MNIST 数据集
【发布时间】:2020-04-15 07:15:18
【问题描述】:

我想在我的数据集上实现堆叠胶囊自动编码器(请参阅 here)。在实施时,我面临以下问题:

MNIST 数据集加载如下:

tfds.load(name='mnist', split=subset, **kwargs).repeat().batch(batch_size)
<DatasetV1Adapter shapes: {label: (?,), image: (?, 28, 28, 1)}, types: {label: tf.int64, image: tf.uint8}>

我正在通过替换上面的代码来加载我的数据集,如下所示:

img_list = []
for img in glob.glob("update_207/*.png"):
  n= cv2.imread(img,0)
  img_1 = tf.convert_to_tensor(np.array(n.resize((2000, 1200, 1))))
  img_list.append(img_1) 
tf.data.Dataset.from_tensor_slices(img_list).repeat().batch(batch_size)
<DatasetV1Adapter shapes: (?,), types: tf.float32>

我是 Tensorflow 的新手,因此请建议对我的代码进行更改,以便我的数据集具有与 MNIST 相似的形状和类型。

【问题讨论】:

    标签: python tensorflow tensorflow-datasets


    【解决方案1】:

    最好详细说明“相似的形状和类型”的含义。在您的情况下,您的输入图像看起来比 mnist 图像大得多。这意味着您必须将它们调整为 28x28 像素。

    如果您让我们知道目前缺少什么,我们或许能够更好地帮助您!

    【讨论】:

    • 形状和类型我的意思是这种格式 与 MNIST 相同,当我得到 shape & size of image 目前不是问题。
    【解决方案2】:

    试试这个:

    img_list = []
    for img in glob.glob("photos/*.jpg"):
      n= cv2.imread(img)
      img_1 = tf.convert_to_tensor(np.array(cv2.resize(n, (256, 256))))
      img_list.append(img_1) 
    train_photos = tf.data.Dataset.from_tensor_slices(img_list).repeat().batch(64)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-11
      • 2018-08-06
      • 2017-12-19
      • 2020-06-13
      • 2020-12-24
      • 2022-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多