Total segmentaor 跑高精度分割模块出错

软件版本:5.2.2
问题描述:Total segmentator模块中如果不点fast是进行分割就会报错
If you have questions or suggestions, feel free to open an issue at https://github.com/MIC-DKFZ/nnUNet

force_separate_z: None interpolation order: 0
Traceback (most recent call last):
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Scripts\TotalSegmentator”, line 93, in
main()
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Scripts\TotalSegmentator”, line 86, in main
totalsegmentator(args.input, args.output, args.ml, args.nr_thr_resamp, args.nr_thr_saving,
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Lib\site-packages\totalsegmentator\python_api.py”, line 173, in totalsegmentator
seg = nnUNet_predict_image(input, output, task_id, model=model, folds=folds,
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Lib\site-packages\totalsegmentator\nnunet.py”, line 238, in nnUNet_predict_image
nnUNet_predict(tmp_dir, tmp_dir, tid, model, folds, trainer, tta)
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Lib\site-packages\totalsegmentator\nnunet.py”, line 106, in nnUNet_predict
predict_from_folder(model_folder_name, dir_in, dir_out, folds, save_npz, num_threads_preprocessing,
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Lib\site-packages\nnunet\inference\predict.py”, line 668, in predict_from_folder
return predict_cases_fastest(model, list_of_lists[part_id::num_parts], output_files[part_id::num_parts], folds,
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Lib\site-packages\nnunet\inference\predict.py”, line 468, in predict_cases_fastest
trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name)
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Lib\site-packages\nnunet\training\model_restore.py”, line 140, in load_model_and_checkpoint_files
trainer = restore_model(join(folds[0], “%s.model.pkl” % checkpoint_name), fp16=mixed_precision)
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Lib\site-packages\nnunet\training\model_restore.py”, line 56, in restore_model
info = load_pickle(pkl_file)
File “D:\medical image\image\3Dslicer\Slicer 5.2.2\lib\Python\Lib\site-packages\batchgenerators\utilities\file_and_folder_operations.py”, line 49, in load_pickle
with open(file, mode) as f:
FileNotFoundError: [Errno 2] No such file or directory: ‘C:\Users\xiebin\.totalsegmentator\nnunet\results\nnUNet\3d_fullres\Task254_TotalSegmentator_part4_muscles_1139subj\nnUNetTrainerV2_ep4000_nomirror__nnUNetPlansv2.1\fold_0\model_final_checkpoint.model.pkl’
Exception ignored in: <totalsegmentator.libs.DummyFile object at 0x00000222F6463B20>
AttributeError: ‘DummyFile’ object has no attribute ‘flush’

从给出的错误追踪中,我们可以分析出以下几点:

  1. 主要错误FileNotFoundError,这意味着程序试图打开一个不存在的文件。错误详细信息为:[Errno 2] No such file or directory: ‘C:\Users\xiebin\.totalsegmentator\nnunet\results\nnUNet\3d_fullres\Task254_TotalSegmentator_part4_muscles_1139subj\nnUNetTrainerV2_ep4000_nomirror__nnUNetPlansv2.1\fold_0\model_final_checkpoint.model.pkl’。这说明程序在尝试加载一个模型文件时,没有找到该文件。
  2. 错误来源:这个错误是在执行 load_pickle 函数时产生的,该函数位于 batchgenerators\utilities\file_and_folder_operations.py 文件的第 49 行。
  3. 上下文:在尝试加载模型和检查点文件时,程序首先尝试从给定的路径中恢复模型。这是在 nnunet\training\model_restore.py 文件的 restore_model 函数中完成的。
  4. 其他错误:在错误追踪的最后,还有一个与 DummyFile 对象相关的 AttributeError。这意味着 DummyFile 对象没有 flush 属性。这可能是由于某种异常处理或清理过程中的错误。

可能的解决方案

  1. 检查文件路径:首先,确保文件 model_final_checkpoint.model.pkl 确实存在于指定的目录中。可能的原因是文件被移动、重命名或删除。
  2. 权限问题:确保您有足够的权限访问上述路径和文件。
  3. 代码检查:检查代码中是否正确指定了文件路径,特别是在调用 load_model_and_checkpoint_filesrestore_model 函数时。
  4. DummyFile 错误:这可能是一个次要的错误,但为了完整性,您应该检查与 DummyFile 对象相关的代码,确保正确实现了所有预期的方法和属性。

总之,主要的问题似乎是文件路径问题,确保文件存在并且路径正确是解决这个问题的关键。