# MONAI Label - unable to get the target\_spacing and spatial\_size using heuristic\_planner

**URL:** <https://discourse.slicer.org/t/monai-label-unable-to-get-the-target-spacing-and-spatial-size-using-heuristic-planner/24391>\
**Category:** Support\
**Tags:** monai\
**Created:** [July 19, 2022, 12:00pm UTC](https://discourse.slicer.org/t/monai-label-unable-to-get-the-target-spacing-and-spatial-size-using-heuristic-planner/24391 "2022-07-19T12:00:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hourglassnam](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hourglassnam/32/11796_2.png) [@hourglassnam](https://discourse.slicer.org/u/hourglassnam)\
**Post date:** [July 19, 2022, 12:00pm UTC](https://discourse.slicer.org/t/monai-label-unable-to-get-the-target-spacing-and-spatial-size-using-heuristic-planner/24391/1 "2022-07-19T12:00:03Z")

</div>

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](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/69).

> 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?

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [July 19, 2022, 12:24pm UTC](https://discourse.slicer.org/t/monai-label-unable-to-get-the-target-spacing-and-spatial-size-using-heuristic-planner/24391/2 "2022-07-19T12:24:38Z")

</div>

There is a new and interesting [MONAI Label pathology video](https://www.youtube.com/watch?v=Jy5VTqX4_jo&t=8s) available on Youtube. Does this solve your problem?

In your special case

```auto
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?

---

<div class="post-metadata">

**Author:** ![hourglassnam](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hourglassnam/32/11796_2.png) [@hourglassnam](https://discourse.slicer.org/u/hourglassnam)\
**Post date:** [July 19, 2022, 1:28pm UTC](https://discourse.slicer.org/t/monai-label-unable-to-get-the-target-spacing-and-spatial-size-using-heuristic-planner/24391/3 "2022-07-19T13:28:20Z")

</div>

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](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/64).

> $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?

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [July 19, 2022, 4:03pm UTC](https://discourse.slicer.org/t/monai-label-unable-to-get-the-target-spacing-and-spatial-size-using-heuristic-planner/24391/4 "2022-07-19T16:03:01Z")

</div>

> [@hourglassnam](#):
>
> micro-CT of a plant seed sample

That sounds interesting 🙂

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:

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

```

was set to 1.0 and never changed,

```auto
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.

---

<div class="post-metadata">

**Author:** ![diazandr3s](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/diazandr3s/32/9973_2.png) [@diazandr3s](https://discourse.slicer.org/u/diazandr3s)\
**Post date:** [July 19, 2022, 10:38pm UTC](https://discourse.slicer.org/t/monai-label-unable-to-get-the-target-spacing-and-spatial-size-using-heuristic-planner/24391/5 "2022-07-19T22:38:47Z")

</div>

@rbumm, thanks for sharing your experience 🙂  
@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](https://www.youtube.com/watch?v=3HTh2dqZqew&list=PLtoSVSQ2XzyD4lc-lAacFBzOdv5Ou-9IA&index=3)

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](https://github.com/Project-MONAI/MONAILabel/discussions)
