当前位置:   article > 正文

nnUNet使用教程_batchgenerators

batchgenerators

大佬GitHub:https://github.com/MIC-DKFZ/nnUNet上面写得也很清楚,英文看着嫌麻烦,然后找的很棒的使用教程,最开始的入门教程看的是另一位大佬的

(四:2020.07.28)nnUNet最舒服的训练教程(让我的奶奶也会用nnUNet(上))(21.04.20更新)_花卷汤圆的博客-CSDN博客_nnunet​​​​​​p​​​​​​​p简单总结一下就是:

1.默认为Ubuntu,cuda, pythorch已安装好

2.从github下载nnunet

  1. git clone https://github.com/MIC-DKFZ/nnUNet.git
  2. cd nnUNet
  3. pip install -e .
  4. pip install --upgrade git+https://github.com/FabianIsensee/hiddenlayer.git@more_plotted_details#egg=hiddenlayer

3.创建数据文件夹

 

 主要是创建DATASET那部分的文件,然后设置路径,在home目录中找到.bashrc(ctrl+h),在文件最后输入以下,然后保存退出,并在终端输入source .bashrc更新文档。

  1. export nnUNet_raw_data_base="/home/xx/nnUNetFrame/DATASET/nnUNet_raw"
  2. export nnUNet_preprocessed="/home/xx/nnUNetFrame/DATASET/nnUNet_preprocessed"
  3. export RESULTS_FOLDER="/home/xx/nnUNetFrame/DATASET/nnUNet_trained_models"

4.处理数据

1)思维导图中的小红旗可以通过以下代码生成:

  1. from batchgenerators.utilities.file_and_folder_operations import *
  2. import shutil
  3. import nibabel as nib
  4. import numpy as np
  5. from nnunet.paths import nnUNet_raw_data
  6. from nnunet.dataset_conversion.utils import generate_dataset_json
  7. if __name__ == '__main__':
  8. # this is the data folder from the kits21 github repository, see https://github.com/neheller/kits21
  9. base = '/home/hannah/code/nnUNetFrame/DATASET/nnUNet_raw/nnUNet_raw_data/Task10_GJA'
  10. # Arbitrary task id. This is just to ensure each dataset ha a unique number. Set this to whatever ([0-999]) you
  11. # want
  12. task_id = 10
  13. task_name = "GJA"
  14. resampled_path = join(base, "labelsTr")
  15. nii_all = nib.load(os.path.join(resampled_path, "gja_001.nii.gz"))
  16. arr_all = np.array(nii_all.dataobj)
  17. numb = np.unique(arr_all)
  18. label = {}
  19. for i in range(len(numb)):
  20. label[i] = int(numb[i])
  21. print(label)
  22. generate_dataset_json(output_file=join(base, 'dataset.json'),
  23. imagesTr_dir=join(base, 'imagesTr'),
  24. imagesTs_dir=join(base, 'imagesTs'),
  25. modalities=('mri',),
  26. labels=label,
  27. dataset_name=task_name,
  28. license='nope',
  29. dataset_release='0')
  30. print("done!")

2)思维导图中红圈1转换数据,在终端中输入(-i 后面为转换前的路径)

nnUNet_convert_decathlon_task -i /home/xx/nnUNetFrame/DATASET/nnUNet_raw/nnUNet_raw_data/Task01_brain

3)思维导图中黄圈2预处理数据,在终端中输入(-t 后面为任务编号)

nnUNet_plan_and_preprocess -t 1

4)思维导图中蓝圈3训练,在终端中输入(2d可换,1为任务编号,4为5折交叉验证)

nnUNet_train 2d nnUNetTrainerV2 1 4

5)思维导图中紫圈4测试,在终端中输入(分别是输入、输出路径,任务编号,模型,交叉验证)

nnUNet_prodict -i /home/XX/Task001_brain/imagesTs -o /home/XX/Task001_brain/infersTs -t 1 -m 2d -f 4

后面在跑对比实验的时候,发现好多都是在nnunet上改的,包括unet++,所以如果用惯了,在这上面跑自己的模型跟数据,会很舒服

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/670126
推荐阅读
相关标签
  

闽ICP备14008679号