Skip to content

Commit

Permalink
SegFormer MulticlassAccuracy metric fix (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLandup0 committed Jun 4, 2023
1 parent 7e0a05c commit c256451
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions deepvision/models/segmentation/segformer/segformer_pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(
backend="pytorch",
)
self.softmax_output = softmax_output
self.acc = torchmetrics.Accuracy(task="multiclass", num_classes=num_classes)
if num_classes > 1:
self.acc = torchmetrics.Accuracy(task="multiclass", num_classes=num_classes)

def forward(self, x):
y = self.backbone(x)
Expand Down Expand Up @@ -74,14 +75,15 @@ def training_step(self, train_batch, batch_idx):
on_epoch=True,
prog_bar=True,
)
acc = self.acc(outputs, targets)
self.log(
"acc",
acc,
on_step=True,
on_epoch=True,
prog_bar=True,
)
if self.num_classes > 1:
acc = self.acc(outputs, targets)
self.log(
"acc",
acc,
on_step=True,
on_epoch=True,
prog_bar=True,
)
return loss

def validation_step(self, val_batch, batch_idx):
Expand All @@ -95,12 +97,13 @@ def validation_step(self, val_batch, batch_idx):
on_epoch=True,
prog_bar=True,
)
val_acc = self.acc(outputs, targets)
self.log(
"val_acc",
val_acc,
on_step=True,
on_epoch=True,
prog_bar=True,
)
if self.num_classes > 1:
val_acc = self.acc(outputs, targets)
self.log(
"val_acc",
val_acc,
on_step=True,
on_epoch=True,
prog_bar=True,
)
return loss

0 comments on commit c256451

Please sign in to comment.