Skip to content

Commit

Permalink
fix bug2
Browse files Browse the repository at this point in the history
  • Loading branch information
namsaraeva committed May 29, 2024
1 parent a4b4b92 commit e57b342
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/sparcscore/ml/plmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ def training_step(self, batch):
target = target.unsqueeze(1)
output = self.network(data) # Forward pass, only one output

loss = self.configure_loss()

if self.hparams["loss"] == "huber": # Huber loss
loss = self.configure_loss(output, target, delta=self.hparams["huber_delta"], reduction='mean')
loss = loss(output, target, delta=self.hparams["huber_delta"], reduction='mean')
else: # MSE
loss = self.configure_loss(output, target)
loss = loss(output, target)

self.log('loss/train', loss, on_step=False, on_epoch=True, prog_bar=True)
self.log('mse/train', self.mse(output, target), on_epoch=True, prog_bar=True)
Expand All @@ -234,11 +236,13 @@ def validation_step(self, batch):
data, target = batch
target = target.unsqueeze(1)
output = self.network(data)

loss = self.configure_loss()

if self.hparams["loss"] == "huber": # Huber loss
loss = self.configure_loss(output, target, delta=self.hparams["huber_delta"], reduction='mean')
loss = loss(output, target, delta=self.hparams["huber_delta"], reduction='mean')
else: # MSE
loss = self.configure_loss(output, target)
loss = loss(output, target)

self.log('loss/val', loss, on_step=False, on_epoch=True, prog_bar=True)
self.log('mse/val', self.mse(output, target), on_epoch=True, prog_bar=True)
Expand All @@ -250,11 +254,13 @@ def test_step(self, batch):
data, target = batch
target = target.unsqueeze(1)
output = self.network(data)

loss = self.configure_loss()

if self.hparams["loss"] == "huber": # Huber loss
loss = self.configure_loss(output, target, delta=self.hparams["huber_delta"], reduction='mean')
loss = loss(output, target, delta=self.hparams["huber_delta"], reduction='mean')
else: # MSE
loss = self.configure_loss(output, target)
loss = loss(output, target)

self.log('loss/test', loss, on_step=False, on_epoch=True, prog_bar=True)
self.log('mse/test', self.mse(output, target), on_epoch=True, prog_bar=True)
Expand Down

0 comments on commit e57b342

Please sign in to comment.