0

我有一个模型训练,我得到了这个情节。它超过了音频(大约 70K,大约 5-10 秒)并且没有进行任何增强。我尝试了以下方法以避免过度拟合:

  • 通过减少 GRU 单元的数量和隐藏维度来降低模型的复杂性。
  • 在每一层中添加 dropout。
  • 我尝试过使用更高的数据集。

我不确定我对训练损失和验证损失的计算是否正确。是这样的。我正在使用 drop_last=True 并且我正在使用 CTC 损失标准。

train_data_len = len(train_loader.dataset)
valid_data_len = len(valid_loader.dataset)
epoch_train_loss = 0
epoch_val_loss = 0
train_losses = []
valid_losses = []

    model.train()
    for e in range(n_epochs):
        t0 = time.time()
        #batch loop
        running_loss = 0.0
        for batch_idx, _data in enumerate(train_loader, 1):
            # Calculate output ...
             # bla bla
            loss = criterion(output, labels.float(), input_lengths, label_lengths)
            loss.backward()
            optimizer.step()
            scheduler.step()
            # loss stats
            running_loss += loss.item() * specs.size(0)
                
        t_t = time.time() - t0

            
        ######################    
        # validate the model #
        ######################
        with torch.no_grad():
            model.eval() 
            tv = time.time()
            running_val_loss = 0.0
            for batch_idx_v, _data in enumerate(valid_loader, 1):
                #bla, bla
                val_loss = criterion(output, labels.float(), input_lengths, label_lengths)
                running_val_loss += val_loss.item() * specs.size(0)
        
            print("Epoch {}: Training took {:.2f} [s]\tValidation took: {:.2f} [s]\n".format(e+1, t_t, time.time() - tv))
                
                
        epoch_train_loss = running_loss / train_data_len
        epoch_val_loss = running_val_loss / valid_data_len
        train_losses.append(epoch_train_loss)
        valid_losses.append(epoch_val_loss)
        print('Epoch: {} Losses\tTraining Loss: {:.6f}\tValidation Loss: {:.6f}'.format(
                e+1, epoch_train_loss, epoch_val_loss))
        model.train()

在此处输入图像描述

4

0 回答 0