Skip to content

Conversation

@Jiaqi-Lv
Copy link
Collaborator

@Jiaqi-Lv Jiaqi-Lv commented Nov 13, 2025

This pull request fixes issues with the SCCNN model. Solving issue #969 .

  • Fix model forward function
  • Fix model preproc typing
  • Fix tests
  • Fix model config

Firstly, the unit test is fixed by adding model.preproc(patch) step before calling infer_batch(), pre-processing function is supposed to be applied on the input patch before the model's forward pass in our engines.

In the unit test, assert is changed using numpy's assert function to compare two arrays. Previously what happened was the output could be an empty numpy array of shape (0,2), the assert would still return True, which was wrong and unsafe. Example:

postproc_output = np.array([]).reshape(0, 2)
print(postproc_output)               # []
print(postproc_output.shape)         # (0, 2)
cmp = (postproc_output == [[8, 7]])
print(cmp)                           # [] with shape (0, 2)
print(np.all(cmp))                   # True (!!)

I removed preproc from SCCNN's forward() function. It should not be used here.

Finally, I updated the input resolution for sccnn models, as from the unit test the resolution seems to be 0.25 mpp.

Regarding issue #969 : Previously the test passes, but as preproc was applied in the model's forward function. When I tried to run the model inside the SementicSegmentor engine, preproc was essentially ran twice, once from the dataloader, and once again in the sccnn.forward() function, which meant the input was divided by 255 twice, therefore the model only outputs zeros as the values were too small.

@Jiaqi-Lv Jiaqi-Lv requested a review from Copilot November 13, 2025 17:33
@Jiaqi-Lv Jiaqi-Lv linked an issue Nov 13, 2025 that may be closed by this pull request
Copilot finished reviewing on behalf of Jiaqi-Lv November 13, 2025 17:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes critical issues with the SCCNN model where preprocessing was being applied twice - once in the dataloader and once in the model's forward function - causing the model to output zeros due to values being divided by 255 twice.

Key changes:

  • Removed duplicate preprocessing call from the model's forward function
  • Changed preproc method signature from torch.Tensor to np.ndarray to match actual usage
  • Updated model configurations to use correct resolution (0.25 mpp instead of 0.5 mpp)

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tiatoolbox/models/architecture/sccnn.py Fixed preproc typing to use np.ndarray and removed duplicate preproc call from forward method
tiatoolbox/data/pretrained_model.yaml Updated resolution from 0.5 to 0.25 mpp for both sccnn-crchisto and sccnn-conic models
tests/models/test_arch_sccnn.py Added explicit preproc call before infer_batch and improved assertions using numpy testing functions
Comments suppressed due to low confidence (1)

tiatoolbox/models/architecture/sccnn.py:254

  • The docstring for the preproc method needs to be updated to reflect the signature change. The Args and Returns sections still reference torch.Tensor, but the method signature now uses np.ndarray for both input and output.

Suggested fix:

"""Transforming network input to desired format.

This method is model and dataset specific, meaning that it can be replaced by
user's desired transform function before training/inference.

Args:
    image (np.ndarray): Input images, the array is of the shape HWC.

Returns:
    output (np.ndarray): The transformed input.

"""
        """Transforming network input to desired format.

        This method is model and dataset specific, meaning that it can be replaced by
        user's desired transform function before training/inference.

        Args:
            image (torch.Tensor): Input images, the tensor is of the shape NCHW.

        Returns:
            output (torch.Tensor): The transformed input.

        """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Jiaqi-Lv Jiaqi-Lv requested a review from Copilot November 13, 2025 17:52
@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.27%. Comparing base (1614a1f) to head (dd18765).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #970      +/-   ##
===========================================
- Coverage    99.27%   99.27%   -0.01%     
===========================================
  Files           71       71              
  Lines         9162     9161       -1     
  Branches      1195     1195              
===========================================
- Hits          9096     9095       -1     
  Misses          40       40              
  Partials        26       26              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot finished reviewing on behalf of Jiaqi-Lv November 13, 2025 17:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

tiatoolbox/models/architecture/sccnn.py:252

  • The docstring for preproc still references torch.Tensor types in the Args and Returns sections, but the method signature has been updated to use np.ndarray. The documentation should be updated to match: image (np.ndarray): Input images, the array is of the shape HWC or NCHW. and np.ndarray: The transformed input.
        Args:
            image (torch.Tensor): Input images, the tensor is of the shape NCHW.

        Returns:
            output (torch.Tensor): The transformed input.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shaneahmed shaneahmed changed the title 🐛 Fix sccnn model 🐛 Fix sccnn model Nov 14, 2025
@shaneahmed shaneahmed added the bug Something isn't working label Nov 14, 2025
@shaneahmed shaneahmed added this to the Release v2.0.0 milestone Nov 14, 2025
@shaneahmed shaneahmed changed the title 🐛 Fix sccnn model 🐛 Fix sccnn Model Nov 14, 2025
Copy link
Member

@shaneahmed shaneahmed left a comment

Choose a reason for hiding this comment

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

Thanks @Jiaqi-Lv

@shaneahmed shaneahmed merged commit 3242b1a into develop Nov 14, 2025
27 checks passed
@shaneahmed shaneahmed deleted the fix-sccnn-model branch November 14, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pretrained sccnn models seem to be broken

3 participants