在 Jupyter Notebook 中训练 PyTorch Lightning 模型时,控制台日志输出显得不太自然:
怎么会出现这样无用的重复并分割成这种形式?而且我不确定
模型的训练和验证步骤如下:
Epoch 0: 100%|█████████▉| 2315/2318 [02:05<00:00, 18.41it/s, loss=1.69, v_num=26, acc=0.562]
Validating: 0it [00:00, ?it/s]
Validating: 0%| | 0/1 [00:00<?, ?it/s]
Epoch 0: 100%|██████████| 2318/2318 [02:09<00:00, 17.84it/s, loss=1.72, v_num=26, acc=0.500, val_loss=1.570, val_acc=0.564]
Epoch 1: 100%|█████████▉| 2315/2318 [02:04<00:00, 18.63it/s, loss=1.56, v_num=26, acc=0.594, val_loss=1.570, val_acc=0.564]
Validating: 0it [00:00, ?it/s]
Validating: 0%| | 0/1 [00:00<?, ?it/s]
Epoch 1: 100%|██████████| 2318/2318 [02:08<00:00, 18.07it/s, loss=1.59, v_num=26, acc=0.528, val_loss=1.490, val_acc=0.583]
Epoch 2: 100%|█████████▉| 2315/2318 [02:01<00:00, 19.02it/s, loss=1.53, v_num=26, acc=0.617, val_loss=1.490, val_acc=0.583]
Validating: 0it [00:00, ?it/s]
Validating: 0%| | 0/1 [00:00<?, ?it/s]
Epoch 2: 100%|██████████| 2318/2318 [02:05<00:00, 18.42it/s, loss=1.57, v_num=26, acc=0.500, val_loss=1.460, val_acc=0.589]
期望的是,相同训练的“正确”输出应该是:
Epoch 0: 100%|██████████| 2318/2318 [02:09<00:00, 17.84it/s, loss=1.72, v_num=26, acc=0.500, val_loss=1.570, val_acc=0.564]
Epoch 1: 100%|██████████| 2318/2318 [02:08<00:00, 18.07it/s, loss=1.59, v_num=26, acc=0.528, val_loss=1.490, val_acc=0.583]
Epoch 2: 100%|██████████| 2318/2318 [02:05<00:00, 18.42it/s, loss=1.57, v_num=26, acc=0.500, val_loss=1.460, val_acc=0.589]
怎么会出现这样无用的重复并分割成这种形式?而且我不确定
Validating
行的用途,因为它们似乎没有提供任何信息。模型的训练和验证步骤如下:
def training_step(self, train_batch, batch_idx):
x, y = train_batch
y_hat = self.forward(x)
loss = torch.nn.NLLLoss()(torch.log(y_hat), y.argmax(dim=1))
acc = tm.functional.accuracy(y_hat.argmax(dim=1), y.argmax(dim=1))
self.log("acc", acc, prog_bar=True)
return loss
def validation_step(self, valid_batch, batch_idx):
x, y = valid_batch
y_hat = self.forward(x)
loss = torch.nn.NLLLoss()(torch.log(y_hat), y.argmax(dim=1))
acc = tm.functional.accuracy(y_hat.argmax(dim=1), y.argmax(dim=1))
self.log("val_loss", loss, prog_bar=True)
self.log("val_acc", acc, prog_bar=True)