MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / finalize_configs

Function finalize_configs

examples/FasterRCNN/config.py:238–322  ·  view source on GitHub ↗

Run some sanity checks, and populate some configs from others

(is_training)

Source from the content-addressed store, hash-verified

236
237
238def finalize_configs(is_training):
239 """
240 Run some sanity checks, and populate some configs from others
241 """
242 _C.freeze(False) # populate new keys now
243 if isinstance(_C.DATA.VAL, six.string_types): # support single string (the typical case) as well
244 _C.DATA.VAL = (_C.DATA.VAL, )
245 if isinstance(_C.DATA.TRAIN, six.string_types): # support single string
246 _C.DATA.TRAIN = (_C.DATA.TRAIN, )
247
248 # finalize dataset definitions ...
249 from dataset import DatasetRegistry
250 datasets = list(_C.DATA.TRAIN) + list(_C.DATA.VAL)
251 _C.DATA.CLASS_NAMES = DatasetRegistry.get_metadata(datasets[0], "class_names")
252 _C.DATA.NUM_CATEGORY = len(_C.DATA.CLASS_NAMES) - 1
253
254 assert _C.BACKBONE.NORM in ['FreezeBN', 'SyncBN', 'GN', 'None'], _C.BACKBONE.NORM
255 if _C.BACKBONE.NORM != 'FreezeBN':
256 assert not _C.BACKBONE.FREEZE_AFFINE
257 assert _C.BACKBONE.FREEZE_AT in [0, 1, 2]
258
259 _C.RPN.NUM_ANCHOR = len(_C.RPN.ANCHOR_SIZES) * len(_C.RPN.ANCHOR_RATIOS)
260 assert len(_C.FPN.ANCHOR_STRIDES) == len(_C.RPN.ANCHOR_SIZES)
261 # image size into the backbone has to be multiple of this number
262 _C.FPN.RESOLUTION_REQUIREMENT = _C.FPN.ANCHOR_STRIDES[3] # [3] because we build FPN with features r2,r3,r4,r5
263
264 if _C.MODE_FPN:
265 size_mult = _C.FPN.RESOLUTION_REQUIREMENT * 1.
266 _C.PREPROC.MAX_SIZE = np.ceil(_C.PREPROC.MAX_SIZE / size_mult) * size_mult
267 assert _C.FPN.PROPOSAL_MODE in ['Level', 'Joint']
268 assert _C.FPN.FRCNN_HEAD_FUNC.endswith('_head')
269 assert _C.FPN.MRCNN_HEAD_FUNC.endswith('_head')
270 assert _C.FPN.NORM in ['None', 'GN']
271
272 if _C.FPN.CASCADE:
273 # the first threshold is the proposal sampling threshold
274 assert _C.CASCADE.IOUS[0] == _C.FRCNN.FG_THRESH
275 assert len(_C.CASCADE.BBOX_REG_WEIGHTS) == len(_C.CASCADE.IOUS)
276
277 if is_training:
278 train_scales = _C.PREPROC.TRAIN_SHORT_EDGE_SIZE
279 if isinstance(train_scales, (list, tuple)) and train_scales[1] - train_scales[0] > 100:
280 # don't autotune if augmentation is on
281 os.environ['TF_CUDNN_USE_AUTOTUNE'] = '0'
282 os.environ['TF_AUTOTUNE_THRESHOLD'] = '1'
283 assert _C.TRAINER in ['horovod', 'replicated'], _C.TRAINER
284
285 lr = _C.TRAIN.LR_SCHEDULE
286 if isinstance(lr, six.string_types):
287 if lr.endswith("x"):
288 LR_SCHEDULE_KITER = {
289 "{}x".format(k):
290 [180 * k - 120, 180 * k - 40, 180 * k]
291 for k in range(2, 10)}
292 LR_SCHEDULE_KITER["1x"] = [120, 160, 180]
293 _C.TRAIN.LR_SCHEDULE = [x * 1000 for x in LR_SCHEDULE_KITER[lr]]
294 else:
295 _C.TRAIN.LR_SCHEDULE = eval(lr)

Callers 4

evaluate_rcnnFunction · 0.90
predict.pyFile · 0.90
train.pyFile · 0.90
data.pyFile · 0.90

Calls 5

get_num_gpuFunction · 0.90
freezeMethod · 0.80
get_metadataMethod · 0.80
formatMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected