# load noad from file

**URL:** <https://discourse.slicer.org/t/load-noad-from-file/27897>\
**Category:** Support\
**Created:** [February 18, 2023, 4:52am UTC](https://discourse.slicer.org/t/load-noad-from-file/27897 "2023-02-18T04:52:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![missile](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/missile/32/18447_2.png) [@missile](https://discourse.slicer.org/u/missile)\
**Post date:** [February 18, 2023, 4:52am UTC](https://discourse.slicer.org/t/load-noad-from-file/27897/1 "2023-02-18T04:52:33Z")

</div>

Hii,  
I am having trouble applying the module in slicer 5.0.2. My situation isthe stl file stores the annotation results of CT data, and I want to convert it to nii format for deep learning.  
When i press apply, it saysreferenceVolumeNode = slicer.util.loadVolume(reference\_volume\_path), which keeps giving me an error about not being able to load noad from file.2  
Detailed error:  
Traceback (most recent call last):  
File “”, line 7, in   
File “D:\Slicer 5.0.2\bin\Python\slicer\util.py”, line 908, in loadVolume  
return loadNodeFromFile(filename, filetype, properties, returnNode)  
File “D:\Slicer 5.0.2\bin\Python\slicer\util.py”, line 681, in loadNodeFromFile  
raise RuntimeError(errorMessage)  
RuntimeError: Failed to load node from file: D:\change\dicom\2.nii.gz

Below is my code

import os  
import slicer  
stl\_path = r"D:\change\stl"  
image\_path = r"D:\change\dicom"  
out\_path = r"D:\change\nii"  
patients = os.listdir(stl\_path)  
for patient in patients:  
patient\_path = os.path.join(stl\_path, patient)  
stl\_files = os.listdir(patient\_path)  
output\_file\_path = os.path.join(out\_path, patient)  
os.makedirs(output\_file\_path, exist\_ok=True)  
reference\_volume\_path = os.path.join(image\_path, patient+“.nii.gz”)  
referenceVolumeNode = slicer.util.loadVolume(reference\_volume\_path)  
for stl\_file in stl\_files:  
stl\_file\_name = os.path.join(patient\_path, stl\_file)  
output\_file\_name = os.path.join(output\_file\_path, stl\_file[0:-4] + “.nii.gz”)  
segmentationNode = slicer.util.loadSegmentation(stl\_file\_name)  
outputLabelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLLabelMapVolumeNode’)  
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, outputLabelmapVolumeNode,  
referenceVolumeNode)  
slicer.util.saveNode(outputLabelmapVolumeNode, output\_file\_name)  
slicer.mrmlScene.Clear(0)
