TissueImageAnalytics / tiatoolbox

Computational Pathology Toolbox developed by TIA Centre, University of Warwick.
https://warwick.ac.uk/tia
Other
340 stars 71 forks source link

AttributeError: 'IOSegmentorConfig' object has no attribute 'margin' #773

Closed alevangel closed 4 months ago

alevangel commented 5 months ago

Description

I get this error, when trying to perform predict() for Necleus Istance segmentation:

|2024-01-22|09:10:30.167| [WARNING] Unknown scale (no objective_power or mpp)
Traceback (most recent call last):
  File "C:\Users\alevangeli\Anaconda3\envs\dpathology\lib\site-packages\IPython\core\interactiveshell.py", line 3508, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-5d02148da079>", line 1, in <module>
    tile_output = inst_segmentor.predict(
  File "C:\Users\alevangeli\AppData\Roaming\Python\Python38\site-packages\tiatoolbox\models\engine\semantic_segmentor.py", line 1399, in predict
    self._predict_wsi_handle_exception(
  File "C:\Users\alevangeli\AppData\Roaming\Python\Python38\site-packages\tiatoolbox\models\engine\semantic_segmentor.py", line 1249, in _predict_wsi_handle_exception
    raise err  # noqa: TRY201
  File "C:\Users\alevangeli\AppData\Roaming\Python\Python38\site-packages\tiatoolbox\models\engine\semantic_segmentor.py", line 1225, in _predict_wsi_handle_exception
    self._predict_one_wsi(wsi_idx, ioconfig, str(wsi_save_path), mode)
  File "C:\Users\alevangeli\AppData\Roaming\Python\Python38\site-packages\tiatoolbox\models\engine\nucleus_instance_segmentor.py", line 714, in _predict_one_wsi
    tile_info_sets = self._get_tile_info(wsi_proc_shape, ioconfig)
  File "C:\Users\alevangeli\AppData\Roaming\Python\Python38\site-packages\tiatoolbox\models\engine\nucleus_instance_segmentor.py", line 445, in _get_tile_info
    margin = np.array(ioconfig.margin)
AttributeError: 'IOSegmentorConfig' object has no attribute 'margin'

What I Did

This is the input, the file is .tiff extension:

    ioconfig = IOSegmentorConfig(
        input_resolutions=[
            {"units": "baseline", "resolution": 1.0},
        ],
        output_resolutions=[
            {"units": "baseline", "resolution": 1.0},
        ],
        patch_input_shape=(512, 512),
        patch_output_shape=(512, 512),
        stride_shape=(512, 512),
    )

    inst_segmentor = NucleusInstanceSegmentor(
        pretrained_model="hovernet_fast-pannuke",
        num_loader_workers=2,
        num_postproc_workers=2,
        batch_size=4,
    )

    tile_output = inst_segmentor.predict(
        [file_path],
        save_dir="sample_tile_results/",
        mode="wsi",  #wsi, tile
        on_gpu=False,
        crash_on_exception=True,
        patch_input_shape=(512, 512),
        units="baseline",
        resolution=1,
        ioconfig=ioconfig,
    )
shaneahmed commented 5 months ago

If you are doing semantic segmentation you should use SemanticSegmentor engine.

If you would like to use NucleusInstanceSegmentor then you should specify the margin. You can specify the same margin of 128 as used in HoVerNet IOConfig.

shaneahmed commented 4 months ago

I am closing this issue. Please feel free to reopen the issue if the above comment does not answer your question.