当前位置:网站首页>[actual combat] transformer architecture of the major medical segmentation challenges on the list --nnformer
[actual combat] transformer architecture of the major medical segmentation challenges on the list --nnformer
2022-07-07 10:37:00 【Sister Tina】
List of articles
brief introduction : We introduced nnFormer(not-another transFormer), One for 3D Medical image segmentation transformer.

nnFormer Not only the combination of convolution and self attention is used , Self attention mechanism based on local and global volume is also introduced to learn volume representation .
Besides ,nnFormer It is suggested to use jumping attention instead of U-Net Traditional operations in jumping connections in class architecture .
Experiments show that , On three public datasets ,nnFormer Remarkable performance . And nnUNet comparison ,nnFormer Produced HD95 Significantly reduce the ,DSC The results are also comparable . Besides ,nnFormer and nnUNet It is highly complementary in model fusion .nnFormer The code of is also based on nnUNet Changed .
,

therefore , Just use it nnUNet, This part of the code is relatively smooth
This tutorial is difficult :
Never used nnUNet: ️️️️
Have used nnUNet: ️️
The difficulty lies in the installation environment , Download data , Preprocessing data , Training and testing are done with one command . The preliminary work should be done well .
nnFormer Paper download
nnFormer github
install
1. Official system version
Ubuntu 18.01、Python 3.6、PyTorch 1.8.1 and CUDA 10.1 . A complete list of packages and version numbers , see also Conda Environmental documents environment.yml.
- Installation steps
It is recommended to use conda Package manager installs the required packages
git clone https://github.com/282857341/nnFormer.git
( The default download location is different , After downloading, I can't find Baidu )
cd nnFormer ( Cut the whole file into your daily project folder , Easy to use )
conda env create -f environment.yml ( This step will create a file called nnFormer Of conda Environmental Science )
source activate nnFormer
pip install -e .
This step installs , If the network is not good , Most of them will make mistakes . If not , It is recommended to create an environment manually conda create -n nnFormer python=3.6, And install it manually environment.yml The package required in the file .
Download and preprocess the experimental data
Three data sets are officially used , Each data set has its own model,train, inference.
Therefore, the data set used must be specified during the experiment .
This tutorial uses Brain_tumor Data sets , When downloading task01_Braintomor, Rename it to Task03_tumor( In this paper task03 It's just brain tumor, To correspond .)
Students who can't download can go to my online disk to download :
link : https://pan.baidu.com/s/1TChc4yXZjPlv9ApqS-OHkQ Extraction code : c0mj
Limited by online disk upload , altogether 3 Compressed packages , Unzip it and put it in Task03_tumor Under the folder . Contains the following 
Preprocessing data
We need to look like nnUNet like that , Data has a strict format .
First create the following folder 
among DATASET Wherever you put it , For convenience , I put it in nnFormer Inside , The folder level is marked on the picture , Don't get it wrong . The fourth level of this experiment only needs Task03_tumor, Put the folder you just put in .
Be careful : The downloaded data has a dataset.json, The training set and the test set are the same nnFormer Dissimilarity . You can proceed to the next step according to the current division , But there is no data in this test set ground truth, When doing the test, you can't ask dice. If you want to know the performance of the test set , Just follow nnFormer Of dataset.json Re divide imagesTr, imagesTs, labelsTr, labelsTs. nnFormer It is to divide the training set into training set and test set again , So his test set has ground truth.( There's so much to say , Don't know to make it clear )
The initial data has , Next, preprocess
- Open the terminal
cd nnFormerconda activate nnFormernnFormer_convert_decathlon_task -i ../DATASET/nnFormer_raw/nnFormer_raw_data/Task03_tumor
This step will create a new one under the data directory Task003_tumor Folder , And convert the multimodal data into 4 Single mode data , Same as nnUNet The data format to be used is the samennFormer_plan_and_preprocess -t 3
The above preprocessing data is over
Now let's enter the formal practical stage
Modify source code errors
There are several errors in the downloaded code that need to be modified
nnFormer/nnformer/run/default_configuration.pyfile
There is one else The position is not rightnnFormer/nnformer/run/run_train.pyfileimport numpy as no Change to npnnFormer/nnformer/training/network_training/nnFormerTrainerV2_nnformer_tumor.pyfileself.load_pretrain_weightSet to False
train
There are altogether 2 Methods
Either way , First Switch to the following path cd nnFormer
- 1 Use
bash train_inference.sh
The file is downloadednnFormerUnder the home directory , You need to open the file before running , Change the folder address to your own address ,
bash train_inference.sh -c 0 -n nnformer_tumor -t 3
Using this command will perform training and testing 

ps: Make sure the variables have been set before
export nnFormer_raw_data_base='/xxxxxxxx/nnFormer/DATASET/nnFormer_raw'
export nnFormer_preprocessed='/xxxxxx/nnFormer/DATASET/nnFormer_preprocessed'
export RESULTS_FOLDER='/xxxxxxx/nnFormer/DATASET/nnFormer_trained_models'
For the setting of environment variables, see the previous article nnunet
The trained model is saved in
xxxx/nnFormer/DATASET/nnFormer_trained_models/nnFormer/3d_fullres/Task003_tumor/nnFormerTrainerV2_nnformer_tumor__nnFormerPlansv2.1
- 2 Use
nnFormer_train
open train_inference.sh file , You can see in the predict part , The actual call is nnFormer_train function , So we can call this function directly for training .
Use nnFormer_train -h Check the meaning of parameters 
eg. CUDA_VISIBLE_DEVICES=1 nnFormer_train 3d_fullres nnFormerTrainerV2_nnformer_tumor 3 0
- The first parameter : network
- The second parameter : network_trainer
- The third parameter : task, can be task name or task id
- Fourth parameter : fold, Five fold cross ,fold It can be specific x fold (0-4), If it is 5 You have to do everything ,fold=5,or all
test
There are altogether 2 Methods
Either way , First Switch to the following path cd nnFormer
- 1 Use
bash train_inference.sh
The file is downloaded nnFormer Under the home directory , You need to open the file before running , Change the folder address to your own address ,
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-quJrtIVU-1655445035770)(imgs/20220614-150345.png)]
We don't need training here , Reasoning only
bash train_inference.sh -c 0 -n nnformer_tumor -t 3
Be careful : If you don't train , To use this command, you need to manually train Part of the code is commented out . I don't understand the code getopts How to use the set parameters , No matter how you set it on the command line, you can't turn off training . So use this stupid method .
c: stands for the index of your cuda device
n: denotes the suffix of the trainer located at nnFormer/nnformer/training/network_training/
t: denotes the task index
2 Use
nnFormer_predict
open train_inference.sh file , You can see in the predict part , The actual call is nnFormer_predict function , So we can call this function directly to make predictions .
Use nnFormer_predict -h Check the meaning of parameters 
eg: nnFormer_predict -i xxx/nnFormer/DATASET/nnFormer_raw/nnFormer_raw_data/Task003_tumor/imagesTs -o xxx/nnFormer/DATASET/nnFormer_raw/nnFormer_raw_data/Task003_tumor/inferTS/nnformer_tumor -t 3 -m 3d_fullres -f 0 -chk model_best -tr nnFormerTrainerV2_nnformer_tumor
After correct operation , The following will appear 
And then you can do it in OUTPUT_FOLDER Check the segmentation results under the folder .
Because the test data does not ground truth, Therefore, you can only view the segmentation performance manually .
ps: The official data is labeled with test sets , You can find what you need . If there's a label , You can use the following command to find dicepython nnformer/inference_tumor.py nnformer_tumor
Articles are constantly updated , You can pay attention to the official account of WeChat 【 Medical image AI combat camp 】 Get the latest , The official account of the frontier technology in the field of medical image processing . Stick to the practice , Take you hand in hand to do the project , Play the game , Write a paper . All original articles provide theoretical explanation , Experimental code , experimental data . Only practice can grow faster , Pay attention to our , Learn together ~
I am a Tina, I'll see you on our next blog ~
Working during the day and writing at night , cough
If you think it's well written, finally , Please thumb up , Comment on , Collection . Or three times with one click 
边栏推荐
- 1321: [example 6.3] deletion problem (noip1994)
- Trajectory planning for multi-robot systems: Methods and applications 综述阅读笔记
- Yarn的基础介绍以及job的提交流程
- 使用U2-Net深层网络实现——证件照生成程序
- 路由器开发知识汇总
- Openinstall and Hupu have reached a cooperation to mine the data value of sports culture industry
- 简单易修改的弹框组件
- 【作业】2022.7.6 写一个自己的cal函数
- 555 circuit details
- The mobile terminal automatically adjusts the page content and font size by setting rem
猜你喜欢

Socket communication principle and Practice

Mendeley--免费的文献管理工具,给论文自动插入参考文献

php \n 换行无法输出

打算参加安全方面工作,信息安全工程师怎么样,软考考试需要怎么准备?

JMeter installation

Deeply analyze the main contents of erc-4907 agreement and think about the significance of this agreement to NFT market liquidity!

Yarn的基础介绍以及job的提交流程

原型与原型链
![P1031 [NOIP2002 提高组] 均分纸牌](/img/ba/6303f54d652fa7aa89440e314f8718.png)
P1031 [NOIP2002 提高组] 均分纸牌

01 use function to approximate cosine function (15 points)
随机推荐
When there are pointer variable members in the custom type, the return value and parameters of the assignment operator overload must be reference types
软考一般什么时候出成绩呢?在线蹬?
软考中级电子商务师含金量高嘛?
Review of the losers in the postgraduate entrance examination
P1031 [noip2002 improvement group] average Solitaire
MySQL insert data create trigger fill UUID field value
[牛客网刷题 Day5] JZ77 按之字形顺序打印二叉树
1323:【例6.5】活动选择
IDA中常见快捷键
关于easyflash v3.3使用过程的记录
宁愿把简单的问题说一百遍,也不把复杂的问题做一遍
深入理解Apache Hudi异步索引机制
How embedded engineers improve work efficiency
CAS mechanism
leetcode-560:和为 K 的子数组
[daiy5] jz77 print binary tree in zigzag order
根据设备信息进行页面跳转至移动端页面或者PC端页面
使用U2-Net深层网络实现——证件照生成程序
软考中级,软件设计师考试那些内容,考试大纲什么的?
leetcode-303:区域和检索 - 数组不可变