【问题标题】:ImageDataGenerator .next() can this be equivalent to mnist.train.next_batch?ImageDataGenerator .next() 这可以等同于 mnist.train.next_batch 吗?
【发布时间】:2021-07-17 16:02:12
【问题描述】:

大家好,我是 tensorflow 的新手,我在胶囊网络上工作 这就是我的数据集的样子:

 -train
     |-class1
     |-class2
     |-class3

我正在使用 ImageDataGenerator flow_from_directory 从目录名称生成标签:

 train = ImageDataGenerator(rescale= 1/255)
trainData = train.flow_from_directory(dir_path , class_mode='categorical' , target_size=(80, 80), batch_size=batch_size )

这是标签的占位符:

 y = tf.placeholder(shape=[None], dtype=tf.int64, name="y")

我正在关注的教程是在 mnist 数据集上工作,所以他这样做是为了将训练数据提供给模型:

X_batch, y_batch = mnist.train.next_batch(batch_size)
        

我这样做了:

 X_batch, y_batch = trainData.next()

它适用于图像,但不适用于 labell,因为我收到了这个错误:

Cannot feed value of shape (10, 3) for Tensor 'y:0', which has shape '(?,)'

y_batch.shape --> (10, 3) 10 是 batch_size,我猜 3 是类数,我对此感到困惑

有人可以帮忙吗?

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:

    标签不需要占位符,只需使用

    images, labels=next(trainData)
    

    这将返回一个 batch_size 个图像和一个 batch_size 个标签。 标签形状将是 (batch_size, number_of_classes) 图像形状将是 (batch_size, 80, 80,3)

    【讨论】:

      【解决方案2】:

      占位符创建空然后加载数据。 对于不需要创建占位符的标签

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-07
        • 1970-01-01
        • 2014-01-04
        • 1970-01-01
        • 1970-01-01
        • 2022-01-10
        • 1970-01-01
        相关资源
        最近更新 更多