【问题标题】:Incremental Neural Network Training增量神经网络训练
【发布时间】:2021-04-09 00:29:41
【问题描述】:

我正在处理一个非常大的数据集,其中包含数百个用作训练的长视频,并且我正在使用 Google Colab 执行一些测试。我编写的整个代码非常简单,并且使用了 PyTorch。 当我尝试进行训练时,如果我一次使用超过 200 个视频,则 RAM 会在训练期间填满并且 Colab 崩溃。我注意到,如果我使用较少数量的训练视频进行训练,则不会发生这种情况。

出于这个原因,我认为我的模型可以逐步训练,创建如下结构:

model = torch.nn.Sequential( # create a model
    ...
    nn.Softmax(dim=1)
)

MAX_VIDEOS_PER_BATCH = 100
for current_batch in range (0, TOTAL_BATCHES): # Perform TOTAL_BATCHES trainings
    videos = []
    labels = []
    for index, video_file_name in enumerate(os.listdir(VIDEOS_DIR)): # Read 100 videos as training set
        if index < MAX_VIDEOS_PER_BATCH * current_batch:
           continue

        ... # read the video and add it to videos
        ... # add the considered labels to videos list


    video_training = torch.tensor(np.asarray(videos)).float() # (batch x frames x channels x height x width)
    learning_rate = 1e-4
    for t in range(ITERATIONS): # Train the model, if I already trained it the model is not resetted
        y_pred = model(torch.FloatTensor(np.asarray(video_training )))

        loss = loss_fn(y_pred, torch.tensor(labels))
        print("#" + str(t), " loss:" + str(loss.item()))

        model.zero_grad()
        loss.backward()
        with torch.no_grad():
        for param in model.parameters():
            param -= learning_rate * param.grad

我的问题是,这种方法正确吗?我正在以正确的方式训练网络,否则这种批量方法会对模型造成一些损害或偏差?

当我从batch 1转到batch 2时,模型不会丢失之前训练的知识,对吗?

【问题讨论】:

    标签: deep-learning pytorch batch-processing ram training-data


    【解决方案1】:

    这是正确的,但最好的方法是反过来。

    【讨论】:

      猜你喜欢
      • 2011-04-07
      • 1970-01-01
      • 2021-12-12
      • 2010-11-20
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多