Skip to content
Open
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
3 changes: 2 additions & 1 deletion segmentation_models_pytorch/base/heads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import torch.nn as nn

from .modules import Activation


Expand All @@ -10,7 +11,7 @@ def __init__(
in_channels, out_channels, kernel_size=kernel_size, padding=kernel_size // 2
)
upsampling = (
nn.UpsamplingBilinear2d(scale_factor=upsampling)
nn.Upsample(mode="bilinear", scale_factor=upsampling, align_corners=True)
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting align_corners=True changes the upsampling behavior compared to the deprecated UpsamplingBilinear2d which used align_corners=False by default. This could affect model output and should be verified against existing trained models. Consider using align_corners=False to maintain backward compatibility unless the behavior change is intentional.

Suggested change
nn.Upsample(mode="bilinear", scale_factor=upsampling, align_corners=True)
nn.Upsample(mode="bilinear", scale_factor=upsampling, align_corners=False)

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isaaccorley can we keep the previous behaviour with align_corners=False?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually tried this initially but this caused the logit tests to fail. I believe this means that the original pretrained checkpoints used align_corners=True.

if upsampling > 1
else nn.Identity()
)
Expand Down
6 changes: 4 additions & 2 deletions segmentation_models_pytorch/decoders/deeplabv3/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"""

from collections.abc import Iterable, Sequence
from typing import Literal, List
from typing import List, Literal

import torch
from torch import nn
Expand Down Expand Up @@ -105,7 +105,9 @@ def __init__(
)

scale_factor = 4 if output_stride == 16 and encoder_depth > 3 else 2
self.up = nn.UpsamplingBilinear2d(scale_factor=scale_factor)
self.up = nn.Upsample(
mode="bilinear", scale_factor=scale_factor, align_corners=True
)

highres_in_channels = encoder_channels[2]
highres_out_channels = 48 # proposed by authors of paper
Expand Down
2 changes: 1 addition & 1 deletion segmentation_models_pytorch/losses/_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def wing_loss(
idx_smaller = diff_abs < width
idx_bigger = diff_abs >= width

loss[idx_smaller] = width * torch.log(1 + diff_abs[idx_smaller] / curvature)
loss[idx_smaller] = width * torch.log1p(diff_abs[idx_smaller] / curvature)

C = width - width * math.log(1 + width / curvature)
loss[idx_bigger] = loss[idx_bigger] - C
Expand Down
Loading