Skip to content

Fix dims=None in loss #937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions requirements/minimum.old
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pillow==8.0.0
pretrainedmodels==0.7.1
six==1.5.0
timm==0.9.0
torch==1.8.0
torchvision==0.9.0
torch==1.9.0
torchvision==0.10.0
tqdm==4.42.1
11 changes: 8 additions & 3 deletions segmentation_models_pytorch/losses/_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,14 @@ def soft_tversky_score(
"""
assert output.size() == target.size()

output_sum = torch.sum(output, dim=dims)
target_sum = torch.sum(target, dim=dims)
difference = LA.vector_norm(output - target, ord=1, dim=dims)
if dims is not None:
output_sum = torch.sum(output, dim=dims)
target_sum = torch.sum(target, dim=dims)
difference = LA.vector_norm(output - target, ord=1, dim=dims)
else:
output_sum = torch.sum(output)
target_sum = torch.sum(target)
difference = LA.vector_norm(output - target, ord=1)

intersection = (output_sum + target_sum - difference) / 2 # TP
fp = output_sum - intersection
Expand Down