|
a |
|
b/scripts/commands/predict.py |
|
|
1 |
""" |
|
|
2 |
If you use this code, please cite one of the SynthSeg papers: |
|
|
3 |
https://github.com/BBillot/SynthSeg/blob/master/bibtex.bib |
|
|
4 |
|
|
|
5 |
Copyright 2020 Benjamin Billot |
|
|
6 |
|
|
|
7 |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
|
|
8 |
compliance with the License. You may obtain a copy of the License at |
|
|
9 |
https://www.apache.org/licenses/LICENSE-2.0 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software distributed under the License is |
|
|
11 |
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
|
|
12 |
implied. See the License for the specific language governing permissions and limitations under the |
|
|
13 |
License. |
|
|
14 |
""" |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
# imports |
|
|
18 |
from argparse import ArgumentParser |
|
|
19 |
from SynthSeg.predict import predict |
|
|
20 |
|
|
|
21 |
parser = ArgumentParser() |
|
|
22 |
|
|
|
23 |
# Positional arguments |
|
|
24 |
parser.add_argument("path_images", type=str, help="path single image or path of the folders with training labels") |
|
|
25 |
parser.add_argument("path_segmentations", type=str, help="segmentations folder/path") |
|
|
26 |
parser.add_argument("path_model", type=str, help="model file path") |
|
|
27 |
|
|
|
28 |
# labels parameters |
|
|
29 |
parser.add_argument("labels_segmentation", type=str, help="path label list") |
|
|
30 |
parser.add_argument("--neutral_labels", type=int, dest="n_neutral_labels", default=None) |
|
|
31 |
parser.add_argument("--names_list", type=str, dest="names_segmentation", default=None, |
|
|
32 |
help="path list of label names, only used if --vol is specified") |
|
|
33 |
|
|
|
34 |
# Saving paths |
|
|
35 |
parser.add_argument("--post", type=str, dest="path_posteriors", default=None, help="posteriors folder/path") |
|
|
36 |
parser.add_argument("--resampled", type=str, dest="path_resampled", default=None, |
|
|
37 |
help="path/folder of the images resampled at the given target resolution") |
|
|
38 |
parser.add_argument("--vol", type=str, dest="path_volumes", default=None, help="path volume file") |
|
|
39 |
|
|
|
40 |
# Processing parameters |
|
|
41 |
parser.add_argument("--min_pad", type=int, dest="min_pad", default=None, |
|
|
42 |
help="margin of the padding") |
|
|
43 |
parser.add_argument("--cropping", type=int, dest="cropping", default=None, |
|
|
44 |
help="crop volume before processing. Segmentations will have the same size as input image.") |
|
|
45 |
parser.add_argument("--target_res", type=float, dest="target_res", default=1., |
|
|
46 |
help="Target resolution at which segmentations will be given.") |
|
|
47 |
parser.add_argument("--flip", action='store_true', dest="flip", |
|
|
48 |
help="to activate test-time augmentation (right/left flipping)") |
|
|
49 |
parser.add_argument("--topology_classes", type=str, dest="topology_classes", default=None, |
|
|
50 |
help="path list of classes, for topologically enhanced biggest connected component analysis") |
|
|
51 |
parser.add_argument("--smoothing", type=float, dest="sigma_smoothing", default=0.5, |
|
|
52 |
help="var for gaussian blurring of the posteriors") |
|
|
53 |
parser.add_argument("--biggest_component", action='store_true', dest="keep_biggest_component", |
|
|
54 |
help="only keep biggest component in segmentation (recommended)") |
|
|
55 |
|
|
|
56 |
# Architecture parameters |
|
|
57 |
parser.add_argument("--conv_size", type=int, dest="conv_size", default=3, help="size of unet convolution masks") |
|
|
58 |
parser.add_argument("--n_levels", type=int, dest="n_levels", default=5, help="number of levels for unet") |
|
|
59 |
parser.add_argument("--conv_per_level", type=int, dest="nb_conv_per_level", default=2, help="conv par level") |
|
|
60 |
parser.add_argument("--unet_feat", type=int, dest="unet_feat_count", default=24, |
|
|
61 |
help="number of features of unet first layer") |
|
|
62 |
parser.add_argument("--feat_mult", type=int, dest="feat_multiplier", default=2, |
|
|
63 |
help="factor of new feature maps per level") |
|
|
64 |
parser.add_argument("--activation", type=str, dest="activation", default='elu', help="activation function") |
|
|
65 |
|
|
|
66 |
# Evaluation parameters |
|
|
67 |
parser.add_argument("--gt", type=str, default=None, dest="gt_folder", |
|
|
68 |
help="folder containing ground truth segmentations, which triggers the evaluation.") |
|
|
69 |
parser.add_argument("--eval_label_list", type=str, dest="evaluation_labels", default=None, |
|
|
70 |
help="labels to evaluate Dice scores on if gt is provided. Default is the same as label_list.") |
|
|
71 |
parser.add_argument("--incorrect_labels", type=str, default=None, dest="list_incorrect_labels", |
|
|
72 |
help="path list labels to correct.") |
|
|
73 |
parser.add_argument("--correct_labels", type=str, default=None, dest="list_correct_labels", |
|
|
74 |
help="path list correct labels.") |
|
|
75 |
|
|
|
76 |
args = parser.parse_args() |
|
|
77 |
predict(**vars(args)) |