base_config.py 4.36 KB
Newer Older
Yeqing Li's avatar
Yeqing Li committed
1
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
Yeqing Li's avatar
Yeqing Li committed
2
3
4
5
6
7
8
9
10
11
12
13
#
# 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.
Yeqing Li's avatar
Yeqing Li committed
14

Yeqing Li's avatar
Yeqing Li committed
15
16
17
"""Base config template."""


Pengchong Jin's avatar
Pengchong Jin committed
18
19
BACKBONES = [
    'resnet',
20
    'spinenet',
Pengchong Jin's avatar
Pengchong Jin committed
21
22
23
24
]

MULTILEVEL_FEATURES = [
    'fpn',
25
    'identity',
Pengchong Jin's avatar
Pengchong Jin committed
26
27
28
]

# pylint: disable=line-too-long
Yeqing Li's avatar
Yeqing Li committed
29
30
31
32
33
34
35
36
37
38
39
40
41
# For ResNet, this freezes the variables of the first conv1 and conv2_x
# layers [1], which leads to higher training speed and slightly better testing
# accuracy. The intuition is that the low-level architecture (e.g., ResNet-50)
# is able to capture low-level features such as edges; therefore, it does not
# need to be fine-tuned for the detection task.
# Note that we need to trailing `/` to avoid the incorrect match.
# [1]: https://github.com/facebookresearch/Detectron/blob/master/detectron/core/config.py#L198
RESNET_FROZEN_VAR_PREFIX = r'(resnet\d+)\/(conv2d(|_([1-9]|10))|batch_normalization(|_([1-9]|10)))\/'
REGULARIZATION_VAR_REGEX = r'.*(kernel|weight):0$'

BASE_CFG = {
    'model_dir': '',
    'use_tpu': True,
Yeqing Li's avatar
Yeqing Li committed
42
    'strategy_type': 'tpu',
Yeqing Li's avatar
Yeqing Li committed
43
44
45
    'isolate_session_state': False,
    'train': {
        'iterations_per_loop': 100,
Yeqing Li's avatar
Yeqing Li committed
46
        'batch_size': 64,
Yeqing Li's avatar
Yeqing Li committed
47
48
49
50
51
52
        'total_steps': 22500,
        'num_cores_per_replica': None,
        'input_partition_dims': None,
        'optimizer': {
            'type': 'momentum',
            'momentum': 0.9,
Pengchong Jin's avatar
Pengchong Jin committed
53
            'nesterov': True,  # `False` is better for TPU v3-128.
Yeqing Li's avatar
Yeqing Li committed
54
55
56
57
58
59
60
61
62
63
64
65
66
        },
        'learning_rate': {
            'type': 'step',
            'warmup_learning_rate': 0.0067,
            'warmup_steps': 500,
            'init_learning_rate': 0.08,
            'learning_rate_levels': [0.008, 0.0008],
            'learning_rate_steps': [15000, 20000],
        },
        'checkpoint': {
            'path': '',
            'prefix': '',
        },
Pengchong Jin's avatar
Pengchong Jin committed
67
68
69
        # One can use 'RESNET_FROZEN_VAR_PREFIX' to speed up ResNet training
        # when loading from the checkpoint.
        'frozen_variable_prefix': '',
Yeqing Li's avatar
Yeqing Li committed
70
71
        'train_file_pattern': '',
        'train_dataset_type': 'tfrecord',
Pengchong Jin's avatar
Pengchong Jin committed
72
        # TODO(b/142174042): Support transpose_input option.
Yeqing Li's avatar
Yeqing Li committed
73
        'transpose_input': False,
Yeqing Li's avatar
Yeqing Li committed
74
75
76
        'regularization_variable_regex': REGULARIZATION_VAR_REGEX,
        'l2_weight_decay': 0.0001,
        'gradient_clip_norm': 0.0,
Pengchong Jin's avatar
Pengchong Jin committed
77
        'input_sharding': False,
Yeqing Li's avatar
Yeqing Li committed
78
79
    },
    'eval': {
Pengchong Jin's avatar
Pengchong Jin committed
80
        'input_sharding': True,
Yeqing Li's avatar
Yeqing Li committed
81
        'batch_size': 8,
Yeqing Li's avatar
Yeqing Li committed
82
83
84
85
86
87
88
89
90
        'eval_samples': 5000,
        'min_eval_interval': 180,
        'eval_timeout': None,
        'num_steps_per_eval': 1000,
        'type': 'box',
        'use_json_file': True,
        'val_json_file': '',
        'eval_file_pattern': '',
        'eval_dataset_type': 'tfrecord',
Pengchong Jin's avatar
Pengchong Jin committed
91
92
93
        # When visualizing images, set evaluation batch size to 40 to avoid
        # potential OOM.
        'num_images_to_visualize': 0,
Yeqing Li's avatar
Yeqing Li committed
94
95
    },
    'predict': {
Yeqing Li's avatar
Yeqing Li committed
96
        'batch_size': 8,
Yeqing Li's avatar
Yeqing Li committed
97
    },
Pengchong Jin's avatar
Pengchong Jin committed
98
99
    'architecture': {
        'backbone': 'resnet',
Yeqing Li's avatar
Yeqing Li committed
100
101
        'min_level': 3,
        'max_level': 7,
Pengchong Jin's avatar
Pengchong Jin committed
102
103
104
105
106
107
108
        'multilevel_features': 'fpn',
        'use_bfloat16': True,
        # Note that `num_classes` is the total number of classes including
        # one background classes whose index is 0.
        'num_classes': 91,
    },
    'anchor': {
Yeqing Li's avatar
Yeqing Li committed
109
110
111
112
        'num_scales': 3,
        'aspect_ratios': [1.0, 2.0, 0.5],
        'anchor_size': 4.0,
    },
Pengchong Jin's avatar
Pengchong Jin committed
113
114
115
116
117
118
119
    'norm_activation': {
        'activation': 'relu',
        'batch_norm_momentum': 0.997,
        'batch_norm_epsilon': 1e-4,
        'batch_norm_trainable': True,
        'use_sync_bn': False,
    },
Yeqing Li's avatar
Yeqing Li committed
120
121
122
    'resnet': {
        'resnet_depth': 50,
    },
123
124
125
    'spinenet': {
        'model_id': '49',
    },
Yeqing Li's avatar
Yeqing Li committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    'fpn': {
        'fpn_feat_dims': 256,
        'use_separable_conv': False,
        'use_batch_norm': True,
    },
    'postprocess': {
        'use_batched_nms': False,
        'max_total_size': 100,
        'nms_iou_threshold': 0.5,
        'score_threshold': 0.05,
        'pre_nms_num_boxes': 5000,
    },
    'enable_summary': False,
}
# pylint: enable=line-too-long