Skip to content

Commit

Permalink
Fixed DSR (#1486)
Browse files Browse the repository at this point in the history
* fixed DSR squeeze bug

* added comment
  • Loading branch information
phcarval authored Jan 4, 2024
1 parent 5f25510 commit df50c0b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/anomalib/models/dsr/torch_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def forward(self, batch: Tensor, anomaly_map_to_generate: Tensor | None = None)
).detach()
image_score = torch.amax(out_mask_averaged, dim=(2, 3)).squeeze()

# prevent crash when image_score is a single value (batch size of 1)
if image_score.size() == torch.Size([]):
image_score = image_score.unsqueeze(0)

out_mask_cv = out_mask_sm_up[:, 1, :, :]

outputs = {"anomaly_map": out_mask_cv, "pred_score": image_score}
Expand Down

0 comments on commit df50c0b

Please sign in to comment.