Skip to content

Commit

Permalink
RegressionModel
Browse files Browse the repository at this point in the history
  • Loading branch information
namsaraeva committed May 14, 2024
1 parent 840813b commit 74a79ea
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/sparcscore/ml/plmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ def __init__(self, model_type="VGG2", **kwargs):
dimensions=128,
num_classes=self.hparams["num_classes"])

## add deprecated type for backward compatability
## add deprecated type for backward compatibility
elif model_type == "VGG1_old":
self.network = _VGG1(in_channels=self.hparams["num_in_channels"],
cfg = "B",
dimensions=128,
num_classes=self.hparams["num_classes"])

## add deprecated type for backward compatability
## add deprecated type for backward compatibility
elif model_type == "VGG2_old":
self.network = _VGG2(in_channels=self.hparams["num_in_channels"],
cfg = "B",
Expand Down Expand Up @@ -123,7 +123,7 @@ def training_step(self, batch, batch_idx):
output_softmax = self.network(data)
loss = F.nll_loss(output_softmax, label)

#calculate accuracy
#calculate accuracy
probabilities = torch.exp(output_softmax)
pred_labels = torch.argmax(probabilities, dim=1)
acc = self.accuracy(pred_labels, label)
Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(self, model_type="VGG2_regression", **kwargs):

# Define the regression model
if model_type == "VGG2_regression":
self.network = VGG2_regression(in_channels=self.hparams["num_in_channels"], cfg="B")
self.network = VGG2_regression(in_channels=self.hparams["num_in_channels"], cfg="B", cfg_MLP="A")

# Initialize metrics for regression model
self.mse = torchmetrics.MeanSquaredError() # MSE metric for regression
Expand All @@ -200,9 +200,9 @@ def configure_optimizers(self):
raise ValueError("No optimizer specified in hparams")
return optimizer

def training_step(self, batch, batch_idx):
def training_step(self, batch):
data, target = batch
output = self.network(data) # Forward pass, only classification, no softmax
output = self.network(data) # Forward pass, only one output
loss = F.mse_loss(output, target) # L2 loss

# accuracy metrics for regression???
Expand All @@ -213,7 +213,7 @@ def training_step(self, batch, batch_idx):

return loss

def validation_step(self, batch, batch_idx):
def validation_step(self, batch):
data, target = batch
output = self.network(data)
loss = F.mse_loss(output, target)
Expand All @@ -226,7 +226,7 @@ def validation_step(self, batch, batch_idx):

return loss

def test_step(self, batch, batch_idx):
def test_step(self, batch):
data, target = batch
output = self.network(data)
loss = F.mse_loss(output, target)
Expand Down

0 comments on commit 74a79ea

Please sign in to comment.