|
| 1 | +from sacred import Experiment, Ingredient |
| 2 | + |
| 3 | +faster_rcnn = Ingredient('faster_rcnn') |
| 4 | +train = Ingredient('train') |
| 5 | +validation = Ingredient('validation') |
| 6 | + |
| 7 | + |
| 8 | +@faster_rcnn.config |
| 9 | +def faster_rcnn_default(): |
| 10 | + # Backbone network. |
| 11 | + backbone = 'resnet50_v1b' # base feature network |
| 12 | + # Final R-CNN non-maximum suppression threshold. You can specify < 0 or > 1 to disable NMS. |
| 13 | + nms_thresh = 0.5 |
| 14 | + # Apply R-CNN NMS to top k detection results, use -1 to disable so that every Detection |
| 15 | + # result is used in NMS. |
| 16 | + nms_topk = -1 |
| 17 | + # ROI pooling mode. Currently support 'pool' and 'align'. |
| 18 | + roi_mode = 'align' |
| 19 | + # (height, width) of the ROI region. |
| 20 | + roi_size = (7, 7) |
| 21 | + # Feature map stride with respect to original image. |
| 22 | + # This is usually the ratio between original image size and feature map size. |
| 23 | + # For FPN, use a tuple of ints. |
| 24 | + strides = (4, 8, 16, 32, 64) |
| 25 | + # Clip bounding box prediction to to prevent exponentiation from overflowing. |
| 26 | + clip = 4.14 |
| 27 | + |
| 28 | + # Anchors generation |
| 29 | + # ------------------ |
| 30 | + # The width(and height) of reference anchor box. |
| 31 | + anchor_base_size = 16 |
| 32 | + # The areas of anchor boxes. |
| 33 | + # We use the following form to compute the shapes of anchors: |
| 34 | + # .. math:: |
| 35 | + # width_{anchor} = size_{base} \times scale \times \sqrt{ 1 / ratio} |
| 36 | + # height_{anchor} = size_{base} \times scale \times \sqrt{ratio} |
| 37 | + anchor_aspect_ratio = (0.5, 1, 2) |
| 38 | + # The aspect ratios of anchor boxes. We expect it to be a list or tuple. |
| 39 | + anchor_scales = (2, 4, 8, 16, 32) |
| 40 | + |
| 41 | + # Allocate size for the anchor boxes as (H, W). |
| 42 | + # Usually we generate enough anchors for large feature map, e.g. 128x128. |
| 43 | + # Later in inference we can have variable input sizes, |
| 44 | + # at which time we can crop corresponding anchors from this large |
| 45 | + # anchor map so we can skip re-generating anchors for each input. |
| 46 | + anchor_alloc_size = (384, 384) |
| 47 | + |
| 48 | + # number of channels used in RPN convolutional layers. |
| 49 | + rpn_channel = 256 |
| 50 | + # IOU threshold for NMS. It is used to remove overlapping proposals. |
| 51 | + rpn_nms_thresh = 0.7 |
| 52 | + # Maximum ground-truth number for each example. This is only an upper bound, not |
| 53 | + # necessarily very precise. However, using a very big number may impact the training speed. |
| 54 | + max_num_gt = 100 |
| 55 | + # Gluon normalization layer to use. Default is none which will use frozen |
| 56 | + # batch normalization layer. |
| 57 | + norm_layer = None |
| 58 | + |
| 59 | + # FPN Options |
| 60 | + # ----------- |
| 61 | + # Whether to use FPN. |
| 62 | + use_fpn = True |
| 63 | + # Number of filters for FPN output layers. |
| 64 | + num_fpn_filters = 256 |
| 65 | + |
| 66 | + # Number of convolution layers to use in box head if batch normalization is not frozen. |
| 67 | + num_box_head_conv = 4 |
| 68 | + # Number of filters for convolution layers in box head. |
| 69 | + # Only applicable if batch normalization is not frozen. |
| 70 | + num_box_head_conv_filters = 256 |
| 71 | + # Number of hidden units for the last fully connected layer in box head. |
| 72 | + num_box_head_dense_filters = 1024 |
| 73 | + |
| 74 | + # Input image short side size. |
| 75 | + image_short = 800 |
| 76 | + # Maximum size of input image long side. |
| 77 | + image_max_size = 1333 |
| 78 | + |
| 79 | + # Whether to enable custom model. |
| 80 | + custom_model = True |
| 81 | + # Whether to use automatic mixed precision |
| 82 | + amp = False |
| 83 | + # Whether to allocate memory statically. |
| 84 | + static_alloc = False |
| 85 | + |
| 86 | + |
| 87 | +@train.config |
| 88 | +def train_cfg(): |
| 89 | + # Whether load the imagenet pre-trained base |
| 90 | + pretrained_base = True |
| 91 | + # Batch size during training |
| 92 | + batch_size = 16 |
| 93 | + # starting epoch |
| 94 | + start_epoch = 0 |
| 95 | + # total epoch for training |
| 96 | + epochs = 26 |
| 97 | + |
| 98 | + # Solver |
| 99 | + # ------ |
| 100 | + # Learning rate. |
| 101 | + lr = 0.01 |
| 102 | + # Decay rate of learning rate. |
| 103 | + lr_decay = 0.1 |
| 104 | + # Epochs at which learning rate decays |
| 105 | + lr_decay_epoch = (20, 24) |
| 106 | + # Learning rate scheduler mode. options are step, poly and cosine |
| 107 | + lr_mode = 'step' |
| 108 | + # Number of iterations for warmup. |
| 109 | + lr_warmup = 500 |
| 110 | + # Starging lr warmup factor. |
| 111 | + lr_warmup_factor = 1. / 3. |
| 112 | + # Momentum |
| 113 | + momentum = 0.9 |
| 114 | + # Weight decay |
| 115 | + wd = 1e-4 |
| 116 | + |
| 117 | + # RPN options |
| 118 | + # ----------- |
| 119 | + # Filter top proposals before NMS in training of RPN. |
| 120 | + rpn_train_pre_nms = 12000 |
| 121 | + # Return top proposal results after NMS in training of RPN. |
| 122 | + # Will be set to rpn_train_pre_nms if it is larger than rpn_train_pre_nms. |
| 123 | + rpn_train_post_nms = 2000 |
| 124 | + # RPN box regression transition point from L1 to L2 loss. |
| 125 | + # Set to 0.0 to make the loss simply L1. |
| 126 | + rpn_smoothl1_rho = 0.001 |
| 127 | + # Proposals whose size is smaller than ``min_size`` will be discarded. |
| 128 | + rpn_min_size = 1 |
| 129 | + |
| 130 | + # R-CNN options |
| 131 | + # ------------- |
| 132 | + # Number of samples for RPN targets. |
| 133 | + rcnn_num_samples = 512 |
| 134 | + # Anchor with IOU larger than ``rcnn_pos_iou_thresh`` is regarded as positive samples. |
| 135 | + rcnn_pos_iou_thresh = 0.5 |
| 136 | + # ``rcnn_pos_iou_thresh`` defines how many positive samples |
| 137 | + # (``rcnn_pos_iou_thresh * num_sample``) is to be sampled. |
| 138 | + rcnn_pos_ratio = 0.25 |
| 139 | + # R-CNN box regression transition point from L1 to L2 loss. |
| 140 | + # Set to 0.0 to make the loss simply L1. |
| 141 | + rcnn_smoothl1_rho = 0.001 |
| 142 | + |
| 143 | + # Misc |
| 144 | + # ---- |
| 145 | + # log interval in terms of iterations |
| 146 | + log_interval = 100 |
| 147 | + seed = 233 |
| 148 | + # Whether to enable verbose logging |
| 149 | + verbose = False |
| 150 | + # Whether to enable mixup training |
| 151 | + mixup = False |
| 152 | + # If mixup is enable, disable mixup after ```no_mixup_epochs```. |
| 153 | + no_mixup_epochs = 20 |
| 154 | + # Number of threads for executor for scheduling ops. |
| 155 | + # More threads may incur higher GPU memory footprint, |
| 156 | + # but may speed up throughput. Note that when horovod is used, |
| 157 | + # it is set to 1. |
| 158 | + executor_threads = 4 |
| 159 | + |
| 160 | + |
| 161 | +@validation.config |
| 162 | +def valid_cfg(): |
| 163 | + # Filter top proposals before NMS in testing of RPN. |
| 164 | + rpn_test_pre_nms = 6000 |
| 165 | + # Return top proposal results after NMS in testing of RPN. |
| 166 | + # Will be set to rpn_test_pre_nms if it is larger than rpn_test_pre_nms. |
| 167 | + rpn_test_post_nms = 1000 |
| 168 | + # Epoch interval for validation |
| 169 | + val_interval = 1 |
| 170 | + |
| 171 | + |
| 172 | +ex = Experiment('faster_rcnn_default', ingredients=[train, validation, faster_rcnn]) |
| 173 | + |
| 174 | + |
| 175 | +@ex.config |
| 176 | +def default_configs(): |
| 177 | + # Dataset name. eg. 'coco', 'voc' |
| 178 | + dataset = 'coco' |
| 179 | + # Training with GPUs, you can specify (1,3) for example. |
| 180 | + gpus = (0, 1, 2, 3, 4, 5, 6, 7) |
| 181 | + # Resume from previously saved parameters if not None. |
| 182 | + # For example, you can resume from ./faster_rcnn_xxx_0123.params. |
| 183 | + resume = '' |
| 184 | + # Saving parameter prefix |
| 185 | + save_prefix = '' |
| 186 | + # Saving parameters epoch interval, best model will always be saved. |
| 187 | + save_interval = 1 |
| 188 | + # Use MXNet Horovod for distributed training. Must be run with OpenMPI. |
| 189 | + horovod = False |
| 190 | + # Number of data workers, you can use larger number to accelerate data loading, |
| 191 | + # if your CPU and GPUs are powerful. |
| 192 | + num_workers = 16 |
| 193 | + # KV store options. local, device, nccl, dist_sync, dist_device_sync, |
| 194 | + # dist_async are available. |
| 195 | + kv_store = 'nccl' |
| 196 | + # Whether to disable hybridize the model. Memory usage and speed will decrese. |
| 197 | + disable_hybridization = False |
0 commit comments