【问题标题】:How do you flow_from_directory in keras when your input does not consist in images?当您的输入不包含在图像中时,您如何在 keras 中 flow_from_directory?
【发布时间】:2020-11-27 18:57:07
【问题描述】:

是否有与flow_from_directory 等效的适用于非图像数据的方法?更准确地说,我将我的数据保存为一个由 numpy 数组组成的泡菜文件。数据已经是我训练网络所需的格式;有没有办法通过读取泡菜文件的每一行向量来拟合我的模型?或者,将我的行向量保存为单个泡菜文件(或其他格式)并拟合模型逐个读取它们?

【问题讨论】:

    标签: python keras pickle


    【解决方案1】:

    是的,你可以在 keras 中使用 Generators 来解决这个问题。

    def Generator(File_address, Batch_Size):
        while True:
          pickle_data = []
          with (open("myfile", "rb")) as openfile: #Read pickle file. this is a sample. you can use your way to read the pickle file.
              while True:
                  pickle_data.append(pickle.load(File_address))
          
          for B in range(0, len(pickle_data), Batch_Size):
              X = pickle_data[B:B+Batch_Size]
              Y = Labels[B:B+Batch_Size] #Define your labels
              yield X, Y #Returning data for training.
    

    现在您可以使用您的生成器了:

    train_gen = Generator('Address_to_pickle_file', Batch_Size)
    
    Model.fit(train_gen, epochs=epoch, steps_per_epoch=Number_of_sampels//Batch_Size)
    

    希望这会很有用。 祝你好运。

    【讨论】:

      猜你喜欢
      • 2015-12-13
      • 2014-01-05
      • 2018-11-02
      • 2016-03-26
      • 2014-09-12
      • 2013-02-06
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      相关资源
      最近更新 更多