question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nucleus segmentation of WSI in PNG results in ValueError: MPP is None. Cannot determine scale in terms of MPP.

See original GitHub issue
  • TIA Toolbox version: 1.3.0
  • Python version: 3.7
  • Operating System: Cent OS

Description

Calling NucleusInstanceSegmentor.predict() with H&E (RGB, PNG) whole-slide image files result in the following error:

ValueError: MPP is None. Cannot determine scale in terms of MPP.

What I Did

I used the IOSegmentorConfig to specify the mpp of my inputs and outputs (H&E images in RGB and PNG format), but when I try to perform the segmentation I get an error saying that the MPP is None. Since PNG files don’t contain any metadata info, I was hoping that by specifying it in IOSegmentorConfig will provide that info.

objIOConfig = IOSegmentorConfig(
    input_resolutions=[
        {'units': 'mpp', 'resolution': 0.325}, 
    ],
    output_resolutions=[
        {'units': 'mpp', 'resolution': 0.325}, 
    ],
    margin=128,
    tile_shape=[1024, 1024],
    patch_input_shape=(256, 256),
    patch_output_shape=(256, 256),
    stride_shape=(164, 164),
    save_resolution={'units': 'mpp', 'resolution': 0.325}
)

# Instantiate the nucleus instance segmentor
objInstSegmentor = NucleusInstanceSegmentor(
    pretrained_model="hovernet_fast-pannuke", 
    num_loader_workers=4, 
    num_postproc_workers=4, 
    batch_size=8, 
    auto_generate_mask=False, 
    verbose=False, 
)

# WSI prediction (if ON_GPU=False, this part will take more than a couple of hours to process)
wsi_output = objInstSegmentor.predict(
    ['TestSet_ROI_6291_wsi_he.png'], 
    ioconfig=objIOConfig, 
    masks=None, 
    save_dir=f'./WSITest/', 
    mode="wsi", 
    on_gpu=ON_GPU, 
    crash_on_exception=True, 
)

The error that I encountered in more detail:

Screen Shot 2022-11-04 at 5 19 00 PM Screen Shot 2022-11-04 at 5 19 11 PM

Thank you!

Caleb

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mostafajahanifarcommented, Nov 22, 2022

Dear @Calebium

As you are trying to make predictions on image tiles, it is better to call the predict method in tile mode instead of mode=wsi. If you specify the mode to be wsi, TIAToolbox requires the input to be a WSI structured file with metadata information.

Therefore, an easy solution to your problem is to set the mode in the last method call to tile:

wsi_output = objInstSegmentor.predict(
    ['TestSet_ROI_6291_wsi_he.png'], 
    ioconfig=objIOConfig, 
    masks=None, 
    save_dir=f'./WSITest/', 
    mode="tile",  # NOT `wsi`
    on_gpu=ON_GPU, 
    crash_on_exception=True, 
)

[Extra Suggestion] I noticed you are trying to set the input resolution to “mpp resolution: 0.325” for your input. You should know, this IOConfig is to set the config of image reading with respect to the trained model, not the test data! So, whatever resolution the data has been captured with, if you want to get the best results using TIAToolbox’s HoVerNet, input images to the algorithm should be in “mpp resolution: 0.25”. Now, if your images are saved in a resolution that is different from the images used in the HoVerNet model training, I would suggest you resize the images to “mpp resolution: 0.255” before you process them in order to achieve the best segmentation resolution. However, even without resizing you should obtain acceptable results.

0reactions
mostafajahanifarcommented, Nov 24, 2022

Thank you for your suggestions. If I call the predict method in tile mode with a whole slide image, how is it treated differently than calling with the same image in wsi mode? Thanks!

If you use tile mode, TIAToolbox assumes the input is a plain image. If the input is a path to a png image, the toolbox tries to read it with a simple cv2.imread function (which is not capable of reading WSIs) and append a predefined standard metadata to it. Therefore, reading a WSI in tile mode will raise an external exception (error). However, if you read a png in the WSI mode, because in WSI mode toolbox assumes there is some metadata associated with the input it would not change the metadata (does not append predefined standard metadata to WSI) and instead throws warnings that metadata is missing and won’t be able to do operations that are metadata dependant (such as reading from a specific mpp).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caleb Chan Calebium - GitHub
Nucleus segmentation of WSI in PNG results in ValueError: MPP is None. Cannot determine scale in terms of MPP. TIA Toolbox version: 1.3.0...
Read more >
Segmentation of foci within nuclei - Image.sc Forum
What I need to do is to segment out the foci (cyan arrows), i.e. regions of higher density of this protein. The end...
Read more >
the of and to a in for is on s that by this with i you it not
... officer driver businesses dead unknown respect specified restaurant mike trip ... kerry ghost nobody supposed ordinary configure violation mit stability ...
Read more >
Click here to download - Computer Science
... terms before hotels did send right type because local those using results ... officer driver businesses dead respect unknown specified restaurant mike ......
Read more >
File:Min'yō scale.png - Wikipedia
Scales, consisting of an ordering outside of time by pitch class (no "distinctiveness"), may be used in compositions by multiple composers ("common material"), ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found