nndetection实践经验

#代码地址: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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
nndetection是基于神经网络的检测方法,用于在图像或视频中检测出特定的目标物体。该方法首先使用深度学习算法训练一个神经网络模型,使其能够识别出目标物体的特征。训练过程中,模型会通过大量的样本图像学习不同目标物体的外观特征,并学会如何通过这些特征来判断是否存在目标物体。 在测试阶段,nndetection将目标物体检测问题转化为一个二分类问题。模型会对输入的图像或视频进行推理,判断其中是否存在目标物体,并给出目标物体的位置和边界框。通过使用神经网络进行目标检测,可以比较准确地识别出目标物体,且对于不同尺寸、旋转角度、遮挡等情况也能具有一定的鲁棒性。 与传统的目标检测算法相比,nndetection具有以下优势。首先,神经网络能够通过大规模数据的训练和反向传播算法的优化,学习到更复杂的特征表示,从而提高识别能力。其次,nndetection在处理图片中的目标物体时,能够更快速地进行检测,提高了速度和效率。此外,通过引入卷积层、池化层等结构,nndetection还能够自动学习出图像中的空间信息,更好地适应目标物体在图像中的位置和大小变化。 总而言之,nndetection是一种基于神经网络的目标物体检测方法,通过训练神经网络模型来自动识别图像中的目标物体。该方法在精度、速度和鲁棒性等方面都有较好的表现,对于许多计算机视觉任务具有广泛的应用前景。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值