Error with test.py due to model paths
If test.py
is called outside the project directory, the software gives this output:
... checking: SAG_ST_TORSO ... starting to process: SAG_ST_TORSO ... loaded CT volume in isotropic resolution and PIR orientation Traceback (most recent call last): File "/scratch/ncomte/softwares/vertebrae_segmentation/test.py", line 93, in binary_mask = binary_segmentor(pir_img, models['seg_binary'], mode='overlap', norm=False) File "/scratch/ncomte/softwares/vertebrae_segmentation/segment_spine.py", line 280, in binary_segmentor model = load_spine_segmentor(model_file) File "/scratch/ncomte/softwares/vertebrae_segmentation/segment_spine.py", line 62, in load_spine_segmentor state_dict = torch.load(model_file) File "/scratch/ncomte/pip-installs-3.8/torch/serialization.py", line 594, in load with _open_file_like(f, 'rb') as opened_file: File "/scratch/ncomte/pip-installs-3.8/torch/serialization.py", line 230, in _open_file_like return _open_file(name_or_buffer, mode) File "/scratch/ncomte/pip-installs-3.8/torch/serialization.py", line 211, in init super(_open_file, self).init(open(name, mode)) FileNotFoundError: [Errno 2] No such file or directory: 'models/segmentor_spine.pth'
Can be fixed by setting full paths of the models in load_models
(test.py):
def load_models():
import os
project_root_path = os.path.split(os.path.realpath(__file__))[0]
model_file_seg_binary = os.path.join(project_root_path, 'models/segmentor_spine.pth')
model_file_seg_idv = os.path.join(project_root_path, 'models/segmentor_vertebra.pth')
model_file_loc_sag = os.path.join(project_root_path, 'models/locator_sagittal.pth')
model_file_loc_cor = os.path.join(project_root_path, 'models/locator_coronal.pth')
id_group_model_file = os.path.join(project_root_path, 'models/classifier_group.pth')
id_cer_model_file = os.path.join(project_root_path, 'models/classifier_cervical.pth')
id_thor_model_file = os.path.join(project_root_path, 'models/classifier_thoracic.pth')
id_lum_model_file = os.path.join(project_root_path, 'models/classifier_lumbar.pth')
return {'seg_binary': model_file_seg_binary, 'seg_individual': model_file_seg_idv,
'loc_sagittal': model_file_loc_sag, 'loc_coronal': model_file_loc_cor,
'id_group': id_group_model_file, 'id_cervical': id_cer_model_file,
'id_thoracic': id_thor_model_file, 'id_lumbar': id_lum_model_file}