Skip to content
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

🐛 Fix MapDe dist_filter Shape #914

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions tests/models/test_arch_mapde.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ def test_functionality(remote_sample: Callable) -> None:
output = model.infer_batch(model, batch, device=select_device(on_gpu=ON_GPU))
output = model.postproc(output[0])
assert np.all(output[0:2] == [[19, 171], [53, 89]])


def test_multiclass_output() -> None:
"""Test the architecture for multi-class output."""
multiclass_model = MapDe(num_input_channels=3, num_classes=3)
test_input = torch.rand((1, 3, 252, 252))

output = multiclass_model(test_input)
assert output.shape == (1, 3, 252, 252)
5 changes: 4 additions & 1 deletion tiatoolbox/models/architecture/mapde.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@ def __init__(
dtype=np.float32,
)

dist_filter = np.expand_dims(dist_filter, axis=(0, 1)) # NCHW
# For conv2d, filter shape = (out_channels, in_channels//groups, H, W)
dist_filter = np.expand_dims(dist_filter, axis=(0, 1))
dist_filter = np.repeat(dist_filter, repeats=num_classes * 2, axis=1)
# Need to repeat for out_channels
dist_filter = np.repeat(dist_filter, repeats=num_classes, axis=0)

self.min_distance = min_distance
self.threshold_abs = threshold_abs
Expand Down