<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 PROMISE12 prostate segmentation demo
Preparation
Step1:  3) Make sure you have all the dependencies installed (replacing gpu with cpu for cpu-only mode)
Step2:  Training a network from the command line
The simplest way to use NiftyNet is via the commandline net_segment.py script. Normally, this is done on the command line with a command like this from the NiftyNet root directory
Step3:  Now you have trained (a few iterations of) a deep learning network for medical image segmentation. If you have some time on your hands, you can finish training the network (by leaving off the max_iter argument) and try it out, by running the following command
python net_segment.py inference --conf demos/PROMISE12/promise12_demo_inference_config.ini
or the following python code in the Notebook
Step4:  Otherwise, you can load up some pre-trained weights for the network
<ASSISTANT_TASK:>
Python Code:
import os,sys 
niftynet_path=r'path/to/NiftyNet'
os.chdir(niftynet_path)
Explanation: PROMISE12 prostate segmentation demo
Preparation:
1) Make sure you have set up the PROMISE12 data set. If not, download it from https://promise12.grand-challenge.org/ (registration required) and run data/PROMISE12/setup.py
2) Make sure you are in NiftyNet root, setting niftynet_path correctly to the path with the niftynet folder in it
End of explanation
import pip
#pip.main(['install','-r','requirements-gpu.txt'])
pip.main(['install','-r','requirements-cpu.txt'])
pip.main(['install', 'SimpleITK>=1.0.0'])
Explanation: 3) Make sure you have all the dependencies installed (replacing gpu with cpu for cpu-only mode):
End of explanation
import os
import sys
import niftynet
sys.argv=['','train','-a','net_segment','--conf',os.path.join('demos','PROMISE12','promise12_demo_train_config.ini'),'--max_iter','10']
niftynet.main()
Explanation: Training a network from the command line
The simplest way to use NiftyNet is via the commandline net_segment.py script. Normally, this is done on the command line with a command like this from the NiftyNet root directory:
python net_segment.py train --conf demos/PROMISE12/promise12_demo_train_config.ini --max_iter 10
Notice that we use configuration file that is specific to this experiment. This file contains default settings. Also note that we can override these settings on the command line.
To execute NiftyNet from within the notebook, you can run the following python code:
End of explanation
import os
import sys
import niftynet
sys.argv=['', 'inference','-a','net_segment','--conf',os.path.join('demos','PROMISE12','promise12_demo_inference_config.ini')]
niftynet.main()
Explanation: Now you have trained (a few iterations of) a deep learning network for medical image segmentation. If you have some time on your hands, you can finish training the network (by leaving off the max_iter argument) and try it out, by running the following command
python net_segment.py inference --conf demos/PROMISE12/promise12_demo_inference_config.ini
or the following python code in the Notebook
End of explanation
import os
import sys
import niftynet
sys.argv=['', 'inference','-a','net_segment','--conf',os.path.join('demos','PROMISE12','promise12_demo_inference_config.ini'), '--model_dir', os.path.join('demos','PROMISE12','pretrained')]
niftynet.main()
Explanation: Otherwise, you can load up some pre-trained weights for the network:
python net_segment.py inference --conf demo/PROMISE12/promise12_demo_config.ini --model_dir demo/PROMISE12/pretrained
or the following python code in the Notebook
End of explanation
<END_TASK>