forked from Project-MONAI/MONAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenums.py
298 lines (225 loc) · 6.63 KB
/
enums.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from enum import Enum
from typing import Optional
from monai.utils.deprecate_utils import deprecated
__all__ = [
"NumpyPadMode",
"GridSampleMode",
"InterpolateMode",
"UpsampleMode",
"BlendMode",
"PytorchPadMode",
"GridSamplePadMode",
"Average",
"MetricReduction",
"LossReduction",
"Weight",
"ChannelMatching",
"SkipMode",
"Method",
"TraceKeys",
"InverseKeys",
"CommonKeys",
"PostFix",
"ForwardMode",
"TransformBackends",
]
class NumpyPadMode(Enum):
"""
See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html
"""
CONSTANT = "constant"
EDGE = "edge"
LINEAR_RAMP = "linear_ramp"
MAXIMUM = "maximum"
MEAN = "mean"
MEDIAN = "median"
MINIMUM = "minimum"
REFLECT = "reflect"
SYMMETRIC = "symmetric"
WRAP = "wrap"
EMPTY = "empty"
class GridSampleMode(Enum):
"""
See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
interpolation mode of `torch.nn.functional.grid_sample`
Note:
(documentation from `torch.nn.functional.grid_sample`)
`mode='bicubic'` supports only 4-D input.
When `mode='bilinear'` and the input is 5-D, the interpolation mode used internally will actually be trilinear.
However, when the input is 4-D, the interpolation mode will legitimately be bilinear.
"""
NEAREST = "nearest"
BILINEAR = "bilinear"
BICUBIC = "bicubic"
class InterpolateMode(Enum):
"""
See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html
"""
NEAREST = "nearest"
LINEAR = "linear"
BILINEAR = "bilinear"
BICUBIC = "bicubic"
TRILINEAR = "trilinear"
AREA = "area"
class UpsampleMode(Enum):
"""
See also: :py:class:`monai.networks.blocks.UpSample`
"""
DECONV = "deconv"
NONTRAINABLE = "nontrainable" # e.g. using torch.nn.Upsample
PIXELSHUFFLE = "pixelshuffle"
class BlendMode(Enum):
"""
See also: :py:class:`monai.data.utils.compute_importance_map`
"""
CONSTANT = "constant"
GAUSSIAN = "gaussian"
class PytorchPadMode(Enum):
"""
See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html
"""
CONSTANT = "constant"
REFLECT = "reflect"
REPLICATE = "replicate"
CIRCULAR = "circular"
class GridSamplePadMode(Enum):
"""
See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
"""
ZEROS = "zeros"
BORDER = "border"
REFLECTION = "reflection"
class Average(Enum):
"""
See also: :py:class:`monai.metrics.rocauc.compute_roc_auc`
"""
MACRO = "macro"
WEIGHTED = "weighted"
MICRO = "micro"
NONE = "none"
class MetricReduction(Enum):
"""
See also: :py:class:`monai.metrics.meandice.DiceMetric`
"""
NONE = "none"
MEAN = "mean"
SUM = "sum"
MEAN_BATCH = "mean_batch"
SUM_BATCH = "sum_batch"
MEAN_CHANNEL = "mean_channel"
SUM_CHANNEL = "sum_channel"
class LossReduction(Enum):
"""
See also:
- :py:class:`monai.losses.dice.DiceLoss`
- :py:class:`monai.losses.dice.GeneralizedDiceLoss`
- :py:class:`monai.losses.focal_loss.FocalLoss`
- :py:class:`monai.losses.tversky.TverskyLoss`
"""
NONE = "none"
MEAN = "mean"
SUM = "sum"
class Weight(Enum):
"""
See also: :py:class:`monai.losses.dice.GeneralizedDiceLoss`
"""
SQUARE = "square"
SIMPLE = "simple"
UNIFORM = "uniform"
class ChannelMatching(Enum):
"""
See also: :py:class:`monai.networks.nets.HighResBlock`
"""
PAD = "pad"
PROJECT = "project"
class SkipMode(Enum):
"""
See also: :py:class:`monai.networks.layers.SkipConnection`
"""
CAT = "cat"
ADD = "add"
MUL = "mul"
class Method(Enum):
"""
See also: :py:class:`monai.transforms.croppad.array.SpatialPad`
"""
SYMMETRIC = "symmetric"
END = "end"
class ForwardMode(Enum):
"""
See also: :py:class:`monai.transforms.engines.evaluator.Evaluator`
"""
TRAIN = "train"
EVAL = "eval"
class TraceKeys:
"""Extra meta data keys used for traceable transforms."""
CLASS_NAME = "class"
ID = "id"
ORIG_SIZE = "orig_size"
EXTRA_INFO = "extra_info"
DO_TRANSFORM = "do_transforms"
KEY_SUFFIX = "_transforms"
NONE = "none"
@deprecated(since="0.8.0", msg_suffix="use monai.utils.enums.TraceKeys instead.")
class InverseKeys:
"""
Extra meta data keys used for inverse transforms.
.. deprecated:: 0.8.0
Use :class:`monai.utils.enums.TraceKeys` instead.
"""
CLASS_NAME = "class"
ID = "id"
ORIG_SIZE = "orig_size"
EXTRA_INFO = "extra_info"
DO_TRANSFORM = "do_transforms"
KEY_SUFFIX = "_transforms"
NONE = "none"
class CommonKeys:
"""
A set of common keys for dictionary based supervised training process.
`IMAGE` is the input image data.
`LABEL` is the training or evaluation label of segmentation or classification task.
`PRED` is the prediction data of model output.
`LOSS` is the loss value of current iteration.
`INFO` is some useful information during training or evaluation, like loss value, etc.
"""
IMAGE = "image"
LABEL = "label"
PRED = "pred"
LOSS = "loss"
class PostFix:
"""Post-fixes."""
@staticmethod
def _get_str(prefix, suffix):
return suffix if prefix is None else f"{prefix}_{suffix}"
@staticmethod
def meta(key: Optional[str] = None):
return PostFix._get_str(key, "meta_dict")
@staticmethod
def orig_meta(key: Optional[str] = None):
return PostFix._get_str(key, "orig_meta_dict")
class TransformBackends(Enum):
"""
Transform backends.
"""
TORCH = "torch"
NUMPY = "numpy"
class JITMetadataKeys(Enum):
"""
Keys stored in the metadata file for saved Torchscript models. Some of these are generated by the routines
and others are optionally provided by users.
"""
NAME = "name"
TIMESTAMP = "timestamp"
VERSION = "version"
DESCRIPTION = "description"