fix logging
This commit is contained in:
parent
e389acefa0
commit
144b9d6128
|
|
@ -132,45 +132,39 @@ class Model(pl.LightningModule):
|
||||||
mixed_waveform = batch["noisy"]
|
mixed_waveform = batch["noisy"]
|
||||||
target = batch["clean"]
|
target = batch["clean"]
|
||||||
prediction = self(mixed_waveform)
|
prediction = self(mixed_waveform)
|
||||||
|
|
||||||
loss = self.loss(prediction, target)
|
loss = self.loss(prediction, target)
|
||||||
|
|
||||||
if (
|
self.log(
|
||||||
(self.logger)
|
"train_loss",
|
||||||
and (self.global_step > 50)
|
loss.item(),
|
||||||
and (self.global_step % 50 == 0)
|
on_epoch=True,
|
||||||
):
|
on_step=True,
|
||||||
self.logger.experiment.log_metric(
|
logger=True,
|
||||||
run_id=self.logger.run_id,
|
prog_bar=True,
|
||||||
key="train_loss",
|
|
||||||
value=loss.item(),
|
|
||||||
step=self.global_step,
|
|
||||||
)
|
)
|
||||||
self.log("train_loss", loss.item())
|
|
||||||
return {"loss": loss}
|
return {"loss": loss}
|
||||||
|
|
||||||
def validation_step(self, batch, batch_idx: int):
|
def validation_step(self, batch, batch_idx: int):
|
||||||
|
|
||||||
|
metric_dict = {}
|
||||||
mixed_waveform = batch["noisy"]
|
mixed_waveform = batch["noisy"]
|
||||||
target = batch["clean"]
|
target = batch["clean"]
|
||||||
prediction = self(mixed_waveform)
|
prediction = self(mixed_waveform)
|
||||||
|
|
||||||
loss_val = self.loss(prediction, target)
|
for metric in self.metric:
|
||||||
self.log("val_loss", loss_val.item())
|
value = metric(target, prediction)
|
||||||
|
metric_dict[f"valid_{metric.name}"] = value.item()
|
||||||
|
|
||||||
if (
|
self.log_dict(
|
||||||
(self.logger)
|
metric_dict,
|
||||||
and (self.global_step > 50)
|
on_step=True,
|
||||||
and (self.global_step % 50 == 0)
|
on_epoch=True,
|
||||||
):
|
prog_bar=True,
|
||||||
self.logger.experiment.log_metric(
|
logger=True,
|
||||||
run_id=self.logger.run_id,
|
|
||||||
key="val_loss",
|
|
||||||
value=loss_val.item(),
|
|
||||||
step=self.global_step,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"loss": loss_val}
|
return metric_dict
|
||||||
|
|
||||||
def test_step(self, batch, batch_idx):
|
def test_step(self, batch, batch_idx):
|
||||||
|
|
||||||
|
|
@ -183,44 +177,16 @@ class Model(pl.LightningModule):
|
||||||
value = metric(target, prediction)
|
value = metric(target, prediction)
|
||||||
metric_dict[metric.name] = value
|
metric_dict[metric.name] = value
|
||||||
|
|
||||||
for k, v in metric_dict.items():
|
self.log_dict(
|
||||||
self.logger.experiment.log_metric(
|
metric_dict,
|
||||||
run_id=self.logger.run_id,
|
on_step=True,
|
||||||
key=k,
|
on_epoch=True,
|
||||||
value=v,
|
prog_bar=True,
|
||||||
step=self.global_step,
|
logger=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
return metric_dict
|
return metric_dict
|
||||||
|
|
||||||
def training_epoch_end(self, outputs):
|
|
||||||
train_mean_loss = 0.0
|
|
||||||
for output in outputs:
|
|
||||||
train_mean_loss += output["loss"]
|
|
||||||
train_mean_loss /= len(outputs)
|
|
||||||
|
|
||||||
if self.logger:
|
|
||||||
self.logger.experiment.log_metric(
|
|
||||||
run_id=self.logger.run_id,
|
|
||||||
key="train_loss_epoch",
|
|
||||||
value=train_mean_loss,
|
|
||||||
step=self.current_epoch,
|
|
||||||
)
|
|
||||||
|
|
||||||
def validation_epoch_end(self, outputs):
|
|
||||||
valid_mean_loss = 0.0
|
|
||||||
for output in outputs:
|
|
||||||
valid_mean_loss += output["loss"]
|
|
||||||
valid_mean_loss /= len(outputs)
|
|
||||||
|
|
||||||
if self.logger:
|
|
||||||
self.logger.experiment.log_metric(
|
|
||||||
run_id=self.logger.run_id,
|
|
||||||
key="valid_loss_epoch",
|
|
||||||
value=valid_mean_loss,
|
|
||||||
step=self.current_epoch,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_epoch_end(self, outputs):
|
def test_epoch_end(self, outputs):
|
||||||
|
|
||||||
test_mean_metrics = defaultdict(int)
|
test_mean_metrics = defaultdict(int)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue