【问题标题】:which is the most suitable method for training among model.fit(), model.train_on_batch(), model.fit_generator()这是model.fit()、model.train_on_batch()、model.fit_generator()中最适合训练的方法
【发布时间】:2019-05-24 03:17:17
【问题描述】:

我有一个包含 600 张图像的训练数据集,分辨率为 (512*512*1),分为 2 类(每类 300 张图像)。使用一些增强技术,我将数据集增加到 10000 张图像。经过以下预处理步骤

all_images=np.array(all_images)/255.0
all_images=all_images.astype('float16')
all_images=all_images.reshape(-1,512,512,1)
saved these images to H5 file.

我使用 AlexNet 架构进行分类,其中包含 3 个卷积、3 个重叠的最大池层。 我想知道以下哪种情况最适合使用内存大小限制为 12GB 的 Google Colab 进行训练。

1. model.fit(x,y,validation_split=0.2)
# For this I have to load all data into memory and then applying an AlexNet to data will simply cause Resource-Exhaust error.

2. model.train_on_batch(x,y)
# For this I have written a script which randomly loads the data batch-wise from H5 file into the memory and train on that data. I am confused by the property of train_on_batch() i.e single gradient update. Do this will affect my training procedure or will it be same as model.fit().

3. model.fit_generator() 
# giving the original directory of images to its data_generator function which automatically augments the data and then train using model.fit_generator(). I haven't tried this yet. 

请指导我在这些方法中哪种方法对我来说是最好的。我已经阅读了很多关于 model.fit()、model.train_on_batch() 和 model.fit_generator() 的答案 HereHereHere,但我仍然感到困惑。

【问题讨论】:

    标签: python-3.x tensorflow keras deep-learning computer-vision


    【解决方案1】:

    model.fit - 如果您将数据加载为 numpy-array 并在没有增强的情况下进行训练,则适用。 model.fit_generator - 如果您的数据集太大而无法放入内存中,或者您想即时应用扩充。 model.train_on_batch - 不太常见,通常在一次训练多个模型时使用(例如 GAN)

    【讨论】:

    • 哦,是的,我知道了。非常感谢您的时间和帮助。请指导我最后一件事,我可以将 model.fit_generator() 用于我保存的增强数据,即我已经增强并保存在 numpy 数组中的数据到 H5 文件。
    • 将该H5文件中的随机batch_wise数据加载到内存中假设batchsize为64,然后使用fit_generator()进行训练
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 2018-01-31
    • 1970-01-01
    • 2020-09-16
    • 2020-07-13
    • 2021-05-26
    • 1970-01-01
    相关资源
    最近更新 更多