Skip to content

Conversation

@vqdang
Copy link
Contributor

@vqdang vqdang commented Mar 7, 2022

Carry on from #285 with a dedicated branch for this fix.
Linked to #287

Check list:

  • Check feature extractor integrity
  • Performance gain measurement: 21.67s (new) vs 45.564 (old) using a 4k x 4k WSI

@ByteHexler To add clarification on the origin of this performance issue.

cum_output.extend(sample_outputs)
# TODO: detach or hook this into a parallel process
self._process_predictions(
cum_output, wsi_reader, ioconfig, save_path, cache_dir

self._process_predictions is called every time cum_output is updated. We will process n**2 time compared to the normal n times. As such, depending on the size of the WSI, this can lead to a significant slowdown, and potentially crash the system because many machines won't be able to hold an entire WSI in the memory. In the initial design, we assumed that

which calls with free_prediction=True will free up the prediction in place, however, this did not work as expected.

ByteHexler and others added 3 commits February 14, 2022 14:07
Moved function self._precess_predictions() out of for loop which was causing major (unnecessary) performance loss for segmentation prediction - especially on larger images/wsi (now up to 12x faster)
@codecov
Copy link

codecov bot commented Mar 7, 2022

Codecov Report

Merging #313 (e7d7048) into develop (fbce1b7) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head e7d7048 differs from pull request most recent head b050fa4. Consider uploading reports for the commit b050fa4 to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #313      +/-   ##
===========================================
+ Coverage    99.82%   99.84%   +0.02%     
===========================================
  Files           53       55       +2     
  Lines         5004     5173     +169     
  Branches       823      878      +55     
===========================================
+ Hits          4995     5165     +170     
  Misses           2        2              
+ Partials         7        6       -1     
Impacted Files Coverage Δ
...oolbox/models/engine/nucleus_instance_segmentor.py 98.50% <ø> (ø)
tiatoolbox/models/engine/semantic_segmentor.py 100.00% <100.00%> (ø)
tiatoolbox/cli/__init__.py 100.00% <0.00%> (ø)
tiatoolbox/cli/save_tiles.py 100.00% <0.00%> (ø)
tiatoolbox/cli/slide_info.py 100.00% <0.00%> (ø)
tiatoolbox/cli/stain_norm.py 100.00% <0.00%> (ø)
tiatoolbox/cli/read_bounds.py 100.00% <0.00%> (ø)
tiatoolbox/cli/tissue_mask.py 100.00% <0.00%> (ø)
tiatoolbox/tools/stainnorm.py 100.00% <0.00%> (ø)
tiatoolbox/cli/patch_predictor.py 100.00% <0.00%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fbce1b7...b050fa4. Read the comment docs.

@John-P John-P added the bug Something isn't working label Mar 11, 2022
@John-P John-P changed the title BUG: Fixed performance issue in semantic_segmentor.py BUG: Fixed Performance Issue In semantic_segmentor.py Mar 11, 2022
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 @vqdang
I will merge once @simongraham has approved it.

Copy link
Contributor

@simongraham simongraham left a comment

Choose a reason for hiding this comment

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

Looks fine.

Copy link
Contributor

@simongraham simongraham left a comment

Choose a reason for hiding this comment

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

Looks fine.

@shaneahmed shaneahmed merged commit 5f87565 into develop Apr 8, 2022
@shaneahmed shaneahmed deleted the fix-performance-semantic-segmentor branch April 8, 2022 10:46
@ByteHexler
Copy link
Contributor

@vqdang thank you a lot for implementing the fix. Great work.

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.

Major performance issues when using SemanticSegmentor on larger images/wsi

6 participants