Project-MONAI / MONAILabel

MONAI Label is an intelligent open source image labeling and learning tool.
https://docs.monai.io/projects/label
Apache License 2.0
570 stars 186 forks source link

RuntimeError when "brats_mri_segmentation_v0.2.1" from monaibundle is used. #1051

Open PranayBolloju opened 1 year ago

PranayBolloju commented 1 year ago

Describe the bug MONAI Label server is giving the following error when "brats_mri_segmentation_v0.2.1" is used for brain tumor segmentation.

RuntimeError: Given groups=1, weight of size [16, 4, 3, 3, 3], expected input[1, 240, 240, 240, 160] to have 4 channels, but got 240 channels instead

To Reproduce Steps to reproduce the behavior:

  1. pip install monailabel
  2. monailabel apps --download --name monaibundle --output apps
  3. monailabel datasets --download --name Task01_BrainTumour --output datasets
  4. monailabel start_server --app apps/monaibundle --studies datasets/Task01_BrainTumour/imagesTr --conf models brats_mri_segmentation_v0.2.1
  5. Run the model in 3D slicer with any image from the dataset.

Expected behavior Segmentation should be displayed in 3D slicer.

Screenshots image image

Environment

Ensuring you use the relevant python executable, please paste the output of:

python -c 'import monai; monai.config.print_debug_info()'

================================ Printing MONAI config...

MONAI version: 1.0.0 Numpy version: 1.22.4 Pytorch version: 1.12.1+cpu MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False MONAI rev id: 170093375ce29267e45681fcec09dfa856e1d7e7 MONAI file: C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\monai__init__.py

Optional dependencies: Pytorch Ignite version: 0.4.10 Nibabel version: 4.0.2 scikit-image version: 0.19.3 Pillow version: 9.2.0 Tensorboard version: 2.10.0 gdown version: 4.5.1 TorchVision version: 0.13.1+cpu tqdm version: 4.64.0 lmdb version: 1.3.0 psutil version: 5.9.1 pandas version: 1.4.3 einops version: 0.4.1 transformers version: NOT INSTALLED or UNKNOWN VERSION. mlflow version: NOT INSTALLED or UNKNOWN VERSION. pynrrd version: 0.4.3

ulphypro commented 1 year ago

Dear @diazandr3s

I'll answer associated with your mention.

Now, I'm using one file of sample files(flair, t1, t2 or t1ce), but maybe.. I'm likely to only use t2_nii.gz per one patient later.

Then, should I include other t2.nii.gz files (ex: a1_t2.nii.gz, a2_t2.nii.gz, a3_t2.nii.gz,..., and etc.) in one folder?

I just pressed 'next sample' button, and then it shows greenbox in 3D view. I didn't nothing except pressing 'Next Sample'. I didn't also trained any model.

First, what I want is not to show green box and anything in 3D view when I pressed 'Next Sample' button using MONAI Label module in 3D-Slicer.

Second, and then I want to conduct train to extract brain tumor. How many repetitions should the training be to extract brain tumor as 'Auto Segmentation'?

Third, (so) when I pressed 'Run' button in 'Auto Segmentation' option, brain tumor should be detected its all segment within brain tumor region.

That's all.

Please, answer my three mention above.

diazandr3s commented 1 year ago

Hi @ulphypro,

Now, I'm using one file of sample files(flair, t1, t2 or t1ce), but maybe.. I'm likely to only use t2_nii.gz per one patient later.

Then you should train the model on T2 only.

Then, should I include other t2.nii.gz files (ex: a1_t2.nii.gz, a2_t2.nii.gz, a3_t2.nii.gz,..., and etc.) in one folder?

Yes, put all T2 images from all patients in the same folder.

I just pressed 'next sample' button, and then it shows greenbox in 3D view. I didn't nothing except pressing 'Next Sample'. I didn't also trained any model.

It is strange, if you click on Next Sample, you should only see the image. Please make sure this folder is empty: _datasets/BraTS2021_Training_Data/BraTS202100002/labels/original

How many repetitions should the training be to extract brain tumor as 'Auto Segmentation'?

It is difficult to say. I'd suggest you train for some epochs (~100) and see how the model performs.

bilalcodehub commented 1 year ago

monailabel for brats segmentation is giving a different error: Invalid Model(s) are provided: ['brats_mri_segmentation_v0.3.8'], either not in model zoo or not supported with MONAI Label

The server log is below:

root@turing:/opt/monai# monailabel start_server --app apps/monaibundle --studies datasets/Task01_BrainTumour/imagesTr --conf models brats_mri_segmentation_v0.3.8
Using PYTHONPATH=/opt:

2023-02-12 11:28:28,363 - USING:: version = False
2023-02-12 11:28:28,364 - USING:: app = /opt/monai/apps/monaibundle
2023-02-12 11:28:28,364 - USING:: studies = /opt/monai/datasets/Task01_BrainTumour/imagesTr
2023-02-12 11:28:28,364 - USING:: verbose = INFO
2023-02-12 11:28:28,364 - USING:: conf = [['models', 'brats_mri_segmentation_v0.3.8']]
2023-02-12 11:28:28,364 - USING:: host = 0.0.0.0
2023-02-12 11:28:28,364 - USING:: port = 8000
2023-02-12 11:28:28,364 - USING:: uvicorn_app = monailabel.app:app
2023-02-12 11:28:28,364 - USING:: ssl_keyfile = None
2023-02-12 11:28:28,364 - USING:: ssl_certfile = None
2023-02-12 11:28:28,364 - USING:: ssl_keyfile_password = None
2023-02-12 11:28:28,364 - USING:: ssl_ca_certs = None
2023-02-12 11:28:28,364 - USING:: workers = None
2023-02-12 11:28:28,364 - USING:: limit_concurrency = None
2023-02-12 11:28:28,364 - USING:: access_log = False
2023-02-12 11:28:28,364 - USING:: log_config = None
2023-02-12 11:28:28,364 - USING:: dryrun = False
2023-02-12 11:28:28,364 - USING:: action = start_server
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_API_STR = 
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_PROJECT_NAME = MONAILabel
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_APP_DIR = 
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_STUDIES = 
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_AUTH_ENABLE = False
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_AUTH_DB = 
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_APP_CONF = '{}'
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_TASKS_TRAIN = True
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_TASKS_STRATEGY = True
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_TASKS_SCORING = True
2023-02-12 11:28:28,364 - ENV SETTINGS:: MONAI_LABEL_TASKS_BATCH_INFER = True
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE = cvat
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_URL = http://127.0.0.1:8080
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_USERNAME =
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_PASSWORD = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_API_KEY = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_CACHE_PATH = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_PROJECT = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_ASSET_PATH = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_DSA_ANNOTATION_GROUPS = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_USERNAME = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_PASSWORD = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_CACHE_PATH = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_QIDO_PREFIX = None
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_WADO_PREFIX = None
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_STOW_PREFIX = None
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_FETCH_BY_FRAME = False
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_CONVERT_TO_NIFTI = True
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_SEARCH_FILTER = '{"Modality": "CT"}'
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_CACHE_EXPIRY = 180
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_PROXY_TIMEOUT = 30.0
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DICOMWEB_READ_TIMEOUT = 5.0
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_AUTO_RELOAD = True
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_READ_ONLY = False
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_DATASTORE_FILE_EXT = '["*.nii.gz", "*.nii", "*.nrrd", "*.jpg", "*.png", "*.tif", "*.svs", "*.xml"]'
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_SERVER_PORT = 8000
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_CORS_ORIGINS = '[]'
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_SESSIONS = True
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_SESSION_PATH = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_SESSION_EXPIRY = 3600
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_INFER_CONCURRENCY = -1
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_INFER_TIMEOUT = 600
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_TRACKING_ENABLED = True
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_TRACKING_URI = 
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_ZOO_SOURCE = github
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_ZOO_REPO = Project-MONAI/model-zoo/hosting_storage_v1
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_ZOO_AUTH_TOKEN =
2023-02-12 11:28:28,365 - ENV SETTINGS:: MONAI_LABEL_AUTO_UPDATE_SCORING = True
2023-02-12 11:28:28,365 - 
Allow Origins: ['*']
[2023-02-12 11:28:28,749] [3699] [MainThread] [INFO] (uvicorn.error:75) - Started server process [3699]
[2023-02-12 11:28:28,750] [3699] [MainThread] [INFO] (uvicorn.error:45) - Waiting for application startup.
[2023-02-12 11:28:28,750] [3699] [MainThread] [INFO] (monailabel.interfaces.utils.app:38) - Initializing App from: /opt/monai/apps/monaibundle; studies: /opt/monai/datasets/Task01_BrainTumour/imagesTr; conf: {'models': 'brats_mri_segmentation_v0.3.8'}
[2023-02-12 11:28:28,793] [3699] [MainThread] [INFO] (monailabel.utils.others.class_utils:37) - Subclass for MONAILabelApp Found: <class 'main.MyApp'>

---------------------------------------------------------------------------------------
Invalid Model(s) are provided: ['brats_mri_segmentation_v0.3.8'], either not in model zoo or not supported with MONAI Label
Following are the available models.  You can pass comma (,) separated names to pass multiple
Available bundle with latest tags:
   -c models
        lung_nodule_ct_detection 
        pancreas_ct_dints_segmentation 
        prostate_mri_anatomy 
        renalStructures_UNEST_segmentation 
        spleen_ct_segmentation 
        spleen_deepedit_annotation 
        swin_unetr_btcv_segmentation 
        wholeBrainSeg_Large_UNEST_segmentation
Or provide valid local bundle directories
---------------------------------------------------------------------------------------

[2023-02-12 11:28:32,170] [3699] [MainThread] [ERROR] (uvicorn.error:119) - Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/starlette/routing.py", line 635, in lifespan
    async with self.lifespan_context(app):
  File "/opt/conda/lib/python3.8/site-packages/starlette/routing.py", line 530, in __aenter__
    await self._router.startup()
  File "/opt/conda/lib/python3.8/site-packages/starlette/routing.py", line 612, in startup
    await handler()
  File "/opt/conda/lib/python3.8/site-packages/monailabel/app.py", line 106, in startup_event
    instance = app_instance()
  File "/opt/conda/lib/python3.8/site-packages/monailabel/interfaces/utils/app.py", line 51, in app_instance
    app = c(app_dir=app_dir, studies=studies, conf=conf)
  File "/opt/monai/apps/monaibundle/main.py", line 36, in __init__
    self.models = get_bundle_models(app_dir, conf)
  File "/opt/conda/lib/python3.8/site-packages/monailabel/utils/others/generic.py", line 296, in get_bundle_models
    exit(-1)
  File "/opt/conda/lib/python3.8/_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: -1

[2023-02-12 11:28:32,170] [3699] [MainThread] [ERROR] (uvicorn.error:56) - Application startup failed. Exiting.
EdenSehatAI commented 7 months ago

Hi,

I'm up to the training phase but am always getting this error on the 9th epoch. Why is this the case?

Val 9/50 221/250 , dice_tc: 0.7409106 , dice_wt: 0.837617 , dice_et: 0.78997755 , time 4.82s Val 9/50 222/250 , dice_tc: 0.74006385 , dice_wt: 0.8375687 , dice_et: 0.7895737 , time 4.82s

RuntimeError Traceback (most recent call last) in <cell line: 11>() 9 loss_epochs, 10 trains_epoch, ---> 11 ) = trainer( 12 model=model, 13 train_loader=train_loader,

5 frames /usr/local/lib/python3.10/dist-packages/torch/_utils.py in reraise(self) 692 # instantiate since we don't know how to 693 raise RuntimeError(msg) from None --> 694 raise exception 695 696

RuntimeError: Caught RuntimeError in DataLoader worker process 1. Original Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/nibabel/loadsave.py", line 90, in load stat_result = os.stat(filename) FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/EdenSehat/BraTS2021_Training_Data/TrainingData/TrainingData/BraTS2021_00390/BraTS2021_00390_flair.nii.gz'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py", line 141, in apply_transform return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) File "/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py", line 98, in _apply_transform return transform(data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(data) File "/usr/local/lib/python3.10/dist-packages/monai/transforms/io/dictionary.py", line 162, in call data = self._loader(d[key], reader) File "/usr/local/lib/python3.10/dist-packages/monai/transforms/io/array.py", line 255, in call img = reader.read(filename) File "/usr/local/lib/python3.10/dist-packages/monai/data/imagereader.py", line 908, in read img = nib.load(name, **kwargs) File "/usr/local/lib/python3.10/dist-packages/nibabel/loadsave.py", line 92, in load raise FileNotFoundError(f"No such file or no access: '{filename}'") FileNotFoundError: No such file or no access: '/content/drive/MyDrive/EdenSehat/BraTS2021_Training_Data/TrainingData/TrainingData/BraTS2021_00390/BraTS2021_00390_flair.nii.gz'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py", line 141, in apply_transform return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) File "/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py", line 98, in _apply_transform return transform(data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(data) File "/usr/local/lib/python3.10/dist-packages/monai/transforms/compose.py", line 335, in call result = execute_compose( File "/usr/local/lib/python3.10/dist-packages/monai/transforms/compose.py", line 111, in execute_compose data = apply_transform( File "/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py", line 171, in apply_transform raise RuntimeError(f"applying transform {transform}") from e RuntimeError: applying transform <monai.transforms.io.dictionary.LoadImaged object at 0x7c01153aa680>

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop data = fetcher.fetch(index) File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.10/dist-packages/monai/data/dataset.py", line 112, in getitem return self._transform(index) File "/usr/local/lib/python3.10/dist-packages/monai/data/dataset.py", line 98, in _transform return apply_transform(self.transform, data_i) if self.transform is not None else data_i File "/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py", line 171, in apply_transform raise RuntimeError(f"applying transform {transform}") from e RuntimeError: applying transform <monai.transforms.compose.Compose object at 0x7c01153abee0>

diazandr3s commented 7 months ago

HI @EdenSehatAI,

From the logs, I see the FLAIR sequence is missing for this patient: BraTS2021_00390_flair

FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/EdenSehat/BraTS2021_Training_Data/TrainingData/TrainingData/BraTS2021_00390/BraTS2021_00390_flair.nii.gz'

Can you make sure this file is in the folder?

EdenSehatAI commented 7 months ago

image

diazandr3s commented 7 months ago

Have you checked that the file is in the downloaded folder? That's what the error is about.

TrushalGulhane commented 1 month ago

Screenshot (4989)

segmentation looks fine in 3D but not in other slicers. is it possible to do it in another slice?

diazandr3s commented 1 month ago

Hi @TrushalGulhane,

This may be the typical orientation problem. I'm assuming you are using the BRATS files that have the 4 modalities merged into a single NIfTI. Is that correct?

In the Slicer MONAI Auto3DSeg we also demonstrated a way of using the BRATS models: https://github.com/lassoan/SlicerMONAIAuto3DSeg

Please give it a try.

TrushalGulhane commented 1 month ago

Thank you @diazandr3s

Is is datasets issue? Is there any available dataset that will be working with brats MRI segmentation model. Please provide dataset link if it's available.

diazandr3s commented 2 weeks ago

Thank you @diazandr3s

Is is datasets issue? Is there any available dataset that will be working with brats MRI segmentation model. Please provide dataset link if it's available.

Hi @TrushalGulhane,

I am not aware of another dataset similar to BRATS.

I'm sure you know this, BRATS dataset is a processed dataset composed of four MR sequence co-registered/aligned.

BTW, have you tried using the MONAI Auto3DSeg module in Slicer. There, you can also find the BRATS models for the different tumor types: https://github.com/lassoan/SlicerMONAIAuto3DSeg/

Just download the latest Slicer and then instal Auto3DSeg via the Extension Manager.

Hope this helps,