mr_ct_regression_model_zoo.md 4.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
# Training regression network with weighted sampling of image windows

This page describes how to acquire and use weighted sampler for image regression.

ref:

Berger et al., "An Adaptive Sampling Scheme to Efficiently Train Fully Convolutional Networks for Semantic Segmentation",
[https://arxiv.org/abs/1709.02764](https://arxiv.org/abs/1709.02764)


## Downloading model zoo files

The training data and initial error maps can be downloaded with the command
```bash
net_download mr_ct_regression_model_zoo
```

(Replace `net_download` with `python net_download.py` if you cloned the NiftyNet repository.)


## Initial training
Command line parameters: ``--starting_iter 0 --max_iter 100``
```bash
python net_run.py train \
  -a niftynet.contrib.regression_weighted_sampler.isample_regression.ISampleRegression \
  -c ~/niftynet/extensions/mr_ct_regression/net_isampler.ini \
  --starting_iter 0 --max_iter 100
```

## Generating error maps
Command line parameters: ``--spatial_window_size 240,240,1 --batch_size 4``
modify the inference batch size and window size for efficiency purpose.
With parameter ``--error_map True``
the errors (elementwise squared differences) will be generated to
``~/niftynet/models/mr_ct_regression/error_maps``.
```bash
python net_run.py inference \
  -a niftynet.contrib.regression_weighted_sampler.isample_regression.ISampleRegression \
  -c ~/niftynet/extensions/mr_ct_regression/net_isampler.ini \
  --inference_iter 100 --spatial_window_size 240,240,1 --batch_size 4 --error_map True
```

## Continue training by sampling according to the error maps:
Command line parameters ``--starting_iter -1``
indicate training the model from the most recently saved checkpoint (at iteration 100).
```bash
python net_run.py train \
  -a niftynet.contrib.regression_weighted_sampler.isample_regression.ISampleRegression \
  -c ~/niftynet/extensions/mr_ct_regression/net_isampler.ini \
  --starting_iter -1 --max_iter 200
```

## Combine them together
Alternating in between error map generation and training with new sampling weights:
(from git cloned source code)
```bash
python net_download.py mr_ct_regression_model_zoo
python net_run.py train \
  -a niftynet.contrib.regression_weighted_sampler.isample_regression.ISampleRegression \
  -c ~/niftynet/extensions/mr_ct_regression/net_isampler.ini \
  --starting_iter 0 --max_iter 100
for max_iter in `seq 200 100 5000`
do
  python net_run.py inference \
    -a niftynet.contrib.regression_weighted_sampler.isample_regression.ISampleRegression \
    -c ~/niftynet/extensions/mr_ct_regression/net_isampler.ini \
    --inference_iter -1 --spatial_window_size 240,240,1 --batch_size 4 --error_map True

  python net_run.py train \
    -a niftynet.contrib.regression_weighted_sampler.isample_regression.ISampleRegression \
    -c ~/niftynet/extensions/mr_ct_regression/net_isampler.ini \
    --starting_iter -1 --max_iter $max_iter
done
```
This script runs training for 5000 iterations,
and new sampling weights are generated at every 100 iterations.

To see the training/validation curves using tensorboard:
```bash
tensorboard --logdir ~/niftynet/models/mr_ct_regression/logs
```

## Generating regression output
Finally regression maps on the test set could be generated by
(inference without ``--error_map True`` parameter):
```bash
python net_run.py inference \
  -a niftynet.contrib.regression_weighted_sampler.isample_regression.ISampleRegression \
  -c ~/niftynet/extensions/mr_ct_regression/net_isampler.ini \
90
  --inference_iter -1 --spatial_window_size 240,240,1 --batch_size 4 --error_map False
91 92 93 94 95 96 97 98
```
to generate results on training+validation+test, please set
``--dataset_split_file nofile`` to override the splitting file at
``~/niftynet/models/mr_ct_regression/dataset_split_file.txt``
```bash
python net_run.py inference \
  -a niftynet.contrib.regression_weighted_sampler.isample_regression.ISampleRegression \
  -c ~/niftynet/extensions/mr_ct_regression/net_isampler.ini \
99
  --inference_iter -1 --spatial_window_size 240,240,1 --batch_size 4 --error_map False --dataset_split_file nofile
100 101
```

102
The output can be found at ``~/niftynet/models/mr_ct_regression/isampler_output/``.