MONAI Label - unable to get the target_spacing and spatial_size using heuristic_planner

Dear Slicer community,
I have a few minor questions and one big question on MONAI Label as I try to train from scratch.
So let me start by stating the big question first.
Because I do not know the target_spacing and spatial_size, I tried using the --conf heuristic_planner true command as mentioned in this forum.

monailabel start_server --app /sample-apps/histology --studies /datasets/Task11_BR/imagesTr --conf models deepedit --conf heuristic_planner true --port 8000 --host 127.0.0.1

When I use the command, it gives me the following error message.

[2022-07-19 19:44:29,031] [11632] [MainThread] [INFO] (monailabel.utils.others.planner:35) - Reading datastore metadata for heuristic planner…
0%| | 0/10 [00:00<?, ?it/s]
[2022-07-19 19:44:29,812] [11632] [MainThread] [ERROR] (uvicorn.error:119) - Traceback (most recent call last):
File “C:\ProgramData\Anaconda3\lib\site-packages\starlette\routing.py”, line 635, in lifespan
async with self.lifespan_context(app):
File “C:\ProgramData\Anaconda3\lib\site-packages\starlette\routing.py”, line 530, in aenter
await self._router.startup()
File “C:\ProgramData\Anaconda3\lib\site-packages\starlette\routing.py”, line 612, in startup
await handler()
File “USERSITE\MONAILabel\monailabel\app.py”, line 103, in startup_event
instance = app_instance()
File “USERSITE\MONAILabel\monailabel\interfaces\utils\app.py”, line 51, in app_instance
app = c(app_dir=app_dir, studies=studies, conf=conf)
File “USERSITE\MONAILabel\sample-apps\histology\main.py”, line 89, in init
super().init(
File “USERSITE\MONAILabel\monailabel\interfaces\app.py”, line 90, in init
self._datastore: Datastore = self.init_datastore()
File “USERSITE\MONAILabel\sample-apps\histology\main.py”, line 100, in init_datastore
self.planner.run(datastore)
File “USERSITE\MONAILabel\monailabel\utils\others\planner.py”, line 58, in run
if mtdt[“pixdim”][4] > 0:
KeyError: ‘pixdim’

[2022-07-19 19:44:29,813] [11632] [MainThread] [ERROR] (uvicorn.error:56) - Application startup failed. Exiting.

The histology mentioned above is the copy of the radiology app I created to change labels.
The server works fine without the heuristic planer, and I could not figure out why this might be.
How can I figure out the target_spacing and spatial_size?
Is there any other way?

And here are my minor curiosities.

  1. The data I used were in *.nrrd format. At first, I saved the volumes as Seg##.nrrd and the segmentations as Seg##.seg.nrrd. In return, it gave me the following message. [2022-07-19 14:23:36,675] [13136] [MainThread] [WARNING] (monailabel.datastore.local:583) - IGNORE:: No matching image exists for ‘Seg01.seg’ to add [Seg01.seg.nrrd] I figured this could be due to the .seg part of the naming, so I changed the volume file names to include .seg, just like the segmentation files. Am I allowed to do this? Will this cause any problems during the training process?
  2. Also, when I copied the radiology folder to make the histology folder, the server did not start right when I deleted the segmentation_spleen subclass. I was just curious why this may happen.
  3. Lastly, the changes I made, such as labels and use_pretrained_model false, were not reflected until I made a separate histology folder. Is there any reason behind this?
1 Like

There is a new and interesting MONAI Label pathology video available on Youtube. Does this solve your problem?

In your special case

monailabel start_server --app /sample-apps/histology --studies /datasets/Task11_BR/imagesTr --conf models deepedit 

would probably work out of the box.

Concerning the other questions could maybe @diazandr3s comment?

1 Like

Hello!! Thank you so much for your reply!

The file I am working with is a micro-CT of a plant seed sample, and I am trying to separate the morphology inside to get the volumetric data of each part.

So the pathology app did not fit my purpose.

I needed to change the labels and disable the use_pretrained_model so it would not use the given labels.

When I changed the labels and disable the use_pretrained_model so it would not use the given labels in “MONAILabel/monailabel/deepedit/multilabel/transforms.py” and “MONAILabel/sample-apps/radiology/lib/configs/deepedit.py”, the changes weren’t reflected on the 3D Slicer and gave me the original label such as spleen, liver and etc.

That is why I had to copy the radiology folder and make a new one.

I think the term histology may have caused the confusion.

Sorry about that.

I started the server(big thanks to you) and successfully changed the labels using the given information from the forum.

$Env:PATH += “;C:\Users\njy95\MONAILabel\monailabel\scripts”

monailabel start_server --app C:/Users/njy95/MONAILabel/sample-apps/histology --studies C:/Users/njy95/datasets/Task11_BR/imagesTr --conf models deepedit --port 8000 --host 127.0.0.1

However, I don’t know my dataset’s target spacing and spatial size for the pretraining process.

To be honest, I don’t clearly understand what target_spacing and spatial_size are. I am assuming this is different from the actual pixel value and was hoping that the heuristic planner would give be recommended value.

That is why I used --conf heuristic_planner true, but it did not work.

Can you give me a advise on what the problem could be?

2 Likes

That sounds interesting :slight_smile:

I can only describe our recent approach, @diazandr3s from the MONAI dev team or others will hopefully provide more technical background. As I understood the parameters relate to resizing ML training data in RAM.

For the training of a lung & airway model from CT we have used:

self.target_spacing = (1.0, 1.0, 1.0)  # target space for image

was set to 1.0 and never changed,

self.spatial_size = (128, 128, 64)  # train input size

was initially set to (32,32,32) and later increased by multiplying those values with 2 and 3. Higher values require more video RAM and increased training time, but changed the lung inference from a minecrafty to a more realistic resolution and look. Our goal is to do the next training on a cloud server with (256,256,256) settings. You should probably start out with (32,32,32).

Hope that helps.

2 Likes

@rbumm, thanks for sharing your experience :slight_smile:
@hourglassnam, thanks for opening this thread. It is an interesting use case for MONAI Label.
The heuristic planner uses image metadata and available GPU memory to define spacing and image size for training the deep learning model. It seems the images you’re using don’t have “pixdim” in the metadata.
As @rbumm suggested, you could start with a spacing of (1.0, 1.0, 1.0) and spatial size to (128, 128, 64) and see how that goes, or even the default values as I show in this video: MONAI Label - Training from Scratch - YouTube

You could explore other values after seeing the results you get.

I’m off this week with limited access to the internet. So I’m slow replying. If you want to get help faster, I’d suggest you open a discussion directly in the MONAI Label repo: Discussions · Project-MONAI/MONAILabel · GitHub

1 Like