|
a |
|
b/init.py |
|
|
1 |
import argparse |
|
|
2 |
import os |
|
|
3 |
|
|
|
4 |
|
|
|
5 |
class Options(): |
|
|
6 |
|
|
|
7 |
"""This class defines options used during both training and test time.""" |
|
|
8 |
|
|
|
9 |
def __init__(self): |
|
|
10 |
"""Reset the class; indicates the class hasn't been initailized""" |
|
|
11 |
self.initialized = False |
|
|
12 |
|
|
|
13 |
def initialize(self, parser): |
|
|
14 |
|
|
|
15 |
# basic parameters |
|
|
16 |
parser.add_argument('--images_folder', type=str, default='./Data_folder/images') |
|
|
17 |
parser.add_argument('--labels_folder', type=str, default='./Data_folder/labels') |
|
|
18 |
parser.add_argument('--increase_factor_data', default=1, help='Increase data number per epoch') |
|
|
19 |
parser.add_argument('--preload', type=str, default=None) |
|
|
20 |
parser.add_argument('--gpu_ids', type=str, default='2,3', help='gpu ids: e.g. 0 0,1,2, 0,2. use -1 for CPU') |
|
|
21 |
parser.add_argument('--workers', default=8, type=int, help='number of data loading workers') |
|
|
22 |
|
|
|
23 |
# dataset parameters |
|
|
24 |
parser.add_argument('--network', default='unetr', help='nnunet, unetr') |
|
|
25 |
parser.add_argument('--patch_size', default=(256, 256, 16), help='Size of the patches extracted from the image') |
|
|
26 |
parser.add_argument('--spacing', default=[0.7, 0.7, 3], help='Original Resolution') |
|
|
27 |
parser.add_argument('--resolution', default=None, help='New Resolution, if you want to resample the data in training. I suggest to resample in organize_folder_structure.py, otherwise in train resampling is slower') |
|
|
28 |
parser.add_argument('--batch_size', type=int, default=4, help='batch size, depends on your machine') |
|
|
29 |
parser.add_argument('--in_channels', default=1, type=int, help='Channels of the input') |
|
|
30 |
parser.add_argument('--out_channels', default=1, type=int, help='Channels of the output') |
|
|
31 |
|
|
|
32 |
# training parameters |
|
|
33 |
parser.add_argument('--epochs', default=1000, help='Number of epochs') |
|
|
34 |
parser.add_argument('--lr', default=0.01, help='Learning rate') |
|
|
35 |
parser.add_argument('--benchmark', default=True) |
|
|
36 |
|
|
|
37 |
# Inference |
|
|
38 |
# This is just a trick to make the predict script working, do not touch it now for the training. |
|
|
39 |
parser.add_argument('--result', default=None, help='Keep this empty and go to predict_single_image script') |
|
|
40 |
parser.add_argument('--weights', default=None, help='Keep this empty and go to predict_single_image script') |
|
|
41 |
|
|
|
42 |
self.initialized = True |
|
|
43 |
return parser |
|
|
44 |
|
|
|
45 |
def parse(self): |
|
|
46 |
if not self.initialized: |
|
|
47 |
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
|
|
48 |
parser = self.initialize(parser) |
|
|
49 |
opt = parser.parse_args() |
|
|
50 |
# set gpu ids |
|
|
51 |
if opt.gpu_ids != '-1': |
|
|
52 |
os.environ["CUDA_VISIBLE_DEVICES"] = opt.gpu_ids |
|
|
53 |
return opt |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|