【问题标题】:ImageDataGenerator - Preprocessing X_trainImageDataGenerator - 预处理 X_train
【发布时间】:2020-06-04 18:09:33
【问题描述】:

我有两个数据集。第一个包含图像数据路径,因此是我的输入路径X_train。第二个数据集包含标签,它们是热编码的并且采用特殊格式,它们的形状是 3 维的(图像数量、标签长度、字符可能性),即我的数据集 (n, 8, 36)。标签是y_train 数据。

标签的形状是我为什么要寻找一种方法来批量读取和预处理X_train 并与y_train 数据分开的原因。有没有这样的方法或者你知道如何解决这个问题吗?

非常感谢!

【问题讨论】:

  • 您可以使用 keras 创建自定义生成器

标签: python tensorflow keras conv-neural-network generator


【解决方案1】:

您可以通过创建一个继承自 Sequence class 的类来使用自定义 keras 生成器

另一个 [SO 回答更多细节[(Clarification about keras.utils.Sequence)

这是一个例子

class Custom_Generator(keras.utils.Sequence) :
    def __init__(self,...,datapath, batch_size, ..) :

    def __len__(self) :
        #calculate data len, something like len(train_labels)


    def load_and_preprocess_function(self, label_names, ...):
        #do something...
        #load data for the batch using label names with whatever library

    def __getitem__(self, idx) :
        batch_y = train_labels[idx:idx+batch_size]
        batch_x = self.load_and_preprocess_function()
        return ( batch_x, batch_y )

【讨论】:

  • 非常感谢!如果有问题,我可以通过聊天或邮件回复您吗?那就太好了:-)
  • 如果你有其他问题,希望你能找到堆栈溢出,或者提出一个新问题,以便将来帮助某人
猜你喜欢
  • 2018-08-07
  • 2021-05-06
  • 2019-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多