我是 pytorch 的新手,我正在尝试运行我找到的 github 模型并对其进行测试。所以作者提供了模型和损失函数。
像这样:
#1. Inference the model
model = PhysNet_padding_Encoder_Decoder_MAX(frames=128)
rPPG, x_visual, x_visual3232, x_visual1616 = model(inputs)
#2. Normalized the Predicted rPPG signal and GroundTruth BVP signal
rPPG = (rPPG-torch.mean(rPPG)) /torch.std(rPPG) # normalize
BVP_label = (BVP_label-torch.mean(BVP_label)) /torch.std(BVP_label) # normalize
#3. Calculate the loss
loss_ecg = Neg_Pearson(rPPG, BVP_label)
数据加载
train_loader = torch.utils.data.DataLoader(train_set, batch_size = 20, shuffle = True)
batch = next(iter(train_loader))
data, label1, label2 = batch
inputs= data
假设我想训练这个模型 15 个 epoch。所以这就是我目前所拥有的:我正在尝试设置优化器和训练,但我不确定如何将自定义损失和数据加载与模型联系起来并正确设置 15 epoch 训练。
optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.9)
for epoch in range(15):
....
有什么建议么?