#代码地址:https://github.com/MIC-DKFZ/nnDetection
##建立镜像
docker build -t nndetection:0.1 --build-arg env_det_num_threads=6 --build-arg env_det_verbose=1 .
##建立容器(The docker container expects data and models in its own `/opt/data` and `/opt/models` directories respectively.The directories need to be mounted via docker `-v`. For simplicity and speed, the ENV variables `det_data` and `det_models` can be set in the host system to point to the desired directories.)
docker run --gpus all -v /home/amax/nnDetection-main/data:/opt/data -v /home/amax/nnDetection-main/models:/opt/models -it --shm-size=24gb nndetection:0.1 /bin/bash
docker run --gpus all -v /data/work/nnDetection-main3/data:/opt/data -v /data/work/nnDetection-main3/models:/opt/models -it --shm-size=24gb nndetection:0.3 /bin/bash
##生成数据来测试安装环境(10例)
nndet_example
nndet_example --full [--num_processes] ## --num_processes 8 多线程,数字表示核数。
# 根据例子做标签文件,文件层次结构如下,需要有一个总的dataset.json文件,新建文件夹raw_splitted,新建imagesTr,labelsTr,imageTs,labelTs文件夹,分别存放训练数据,训练标签,测试数据,测试结果
${det_data}
[Task000_Example]
- dataset.yaml # dataset.json works too
[raw_splitted]
[imagesTr]
- case0000_0000.nii.gz # case0000 modality 0
- case0000_0001.nii.gz # case0000 modality 1
- case0001_0000.nii.gz # case0001 modality 0
- case0000_0001.nii.gz # case0001 modality 1
[labelsTr]
- case0000.nii.gz # instance segmentation case0000
- case0000.json # properties of case0000
- case0001.nii.gz # instance segmentation case0001
- case0001.json # properties of case0001
[imagesTs] # optional, same structure as imagesTr
...
[labelsTs] # optional, same structure as labelsTr
...
[Task001_Example1]
...
#dataset.json文件内容如下
task: Task000D3_Example
name: "Example" # [Optional]
dim: 3 # number of spatial dimensions of the data
# Note: need to use integer value which is defined below of target class!
target_class: 1 # [Optional] define class of interest for patient level evaluations
test_labels: True # manually splitted test set
labels: # classes of data set; need to start at 0
"0": "Square"
"1": "SquareHole"
modalities: # modalities of data set; need to start at 0
"0": "CT"
#训练数据,imagesTr文件夹下的文件,文件名末尾都需要加上_0000
- case001_0000.nii.gz # Case ID: case001; Modality: 0
- case001_0001.nii.gz # Case ID: case001; Modality: 1
- case002_0000.nii.gz # Case ID: case002; Modality: 0
- case002_0001.nii.gz # Case ID: case002; Modality: 1
#labelsTr文件夹,里面的每个标签文件需要有对应的json文件,如下,每个实例都需要有类别划分,这个需要根据自己的数据对应制作,否则训练完也没有用
{
"instances": {
"1": 0,
"2": 1
}
}
#开始using nnDetection
#1.数据预处理
nndet_prep 000
#预处理完成后文件结果
[Task000_Example]
[raw_splitted]
[raw_cropped] # only needed for different resampling strategies
[imagesTr] # stores cropped image data; contains npz files
[labelsTr] # stores labels
[preprocessed]
[analysis] # some plots to visualize properties of the underlying data set
[properties] # sufficient for new plans
[labelsTr] # labels in original format (original spacing)
[labelsTs] # optional
[Data identifier; e.g. D3V001_3d]
[imagesTr] # preprocessed data
[labelsTr] # preprocessed labels (resampled spacing)
- {name of plan}.pkl e.g. D3V001_3d.pkl
#自己的数据集预处理
nndet_prep 91
正在上传…重新上传取消
正在上传…重新上传取消
#2.解压训练数据
nndet_unpack ${det_data}/Task000D3_Example/preprocessed/D3V001_3d/imagesTr 6
#3.训练模型
nndet_train 000 --sweep
nndet_train 91
#训练过程有报错,
#3.--sweep option tells nnDetection to look for the best hyparameters for inference by empirically evaluating them on the validation set.
nndet_sweep 000 RetinaUNetV001_D3V001_3d 0
nndet_sweep 91 RetinaUNetV001_D3V001_3d 0
#4.Evaluation can be invoked by the following command (requires access to the model and preprocessed data):
nndet_eval 000 RetinaUNetV001_D3V001_3d 0 --boxes --analyze_boxes
nndet_eval 91 RetinaUNetV001_D3V001_3d 0 --boxes --analyze_boxes
#5.consolodate
nndet_consolidate 000 RetinaUNetV001_D3V001_3d --sweep_boxes
nndet_consolidate 91 --num_folds=1 RetinaUNetV001_D3V001_3d --sweep_boxes
#6.predict
nndet_predict 000 RetinaUNetV001_D3V001_3d --fold -1
nndet_predict 91 RetinaUNetV001_D3V001_3d --fold -1
#结果
在/data/work/models/Task91_innerear/RetinaUNetV001_D3V001_3d/consolidated/test_predictions文件夹下
#将输出结果boxes.pkl转换成nii.gz格式,不知道为什么转换的是val_predictions文件夹,test_predictions不行,在scripts/utils.py下boxes2nii()函数
nndet_boxes2nii 91 --fold -1 RetinaUNetV001_D3V001_3d