(epoch)
| 281 | global_step = [0] |
| 282 | |
| 283 | def save_model(epoch): |
| 284 | arg, aux = mod.get_params() |
| 285 | all_layers = mod.symbol.get_internals() |
| 286 | outs = [] |
| 287 | for stride in config.RPN_FEAT_STRIDE: |
| 288 | num_anchors = config.RPN_ANCHOR_CFG[str(stride)]['NUM_ANCHORS'] |
| 289 | if config.CASCADE > 0: |
| 290 | _name = 'face_rpn_cls_score_stride%d_output' % (stride) |
| 291 | cls_pred = all_layers[_name] |
| 292 | cls_pred = mx.symbol.Reshape(data=cls_pred, |
| 293 | shape=(0, 2, -1, 0)) |
| 294 | |
| 295 | cls_pred = mx.symbol.SoftmaxActivation(data=cls_pred, |
| 296 | mode="channel") |
| 297 | cls_pred = mx.symbol.Reshape(data=cls_pred, |
| 298 | shape=(0, 2 * num_anchors, -1, 0)) |
| 299 | outs.append(cls_pred) |
| 300 | _name = 'face_rpn_bbox_pred_stride%d_output' % stride |
| 301 | rpn_bbox_pred = all_layers[_name] |
| 302 | outs.append(rpn_bbox_pred) |
| 303 | if config.FACE_LANDMARK: |
| 304 | _name = 'face_rpn_landmark_pred_stride%d_output' % stride |
| 305 | rpn_landmark_pred = all_layers[_name] |
| 306 | outs.append(rpn_landmark_pred) |
| 307 | for casid in range(config.CASCADE): |
| 308 | if stride in config.CASCADE_CLS_STRIDES: |
| 309 | _name = 'face_rpn_cls_score_stride%d_cas%d_output' % ( |
| 310 | stride, casid) |
| 311 | cls_pred = all_layers[_name] |
| 312 | cls_pred = mx.symbol.Reshape(data=cls_pred, |
| 313 | shape=(0, 2, -1, 0)) |
| 314 | cls_pred = mx.symbol.SoftmaxActivation(data=cls_pred, |
| 315 | mode="channel") |
| 316 | cls_pred = mx.symbol.Reshape(data=cls_pred, |
| 317 | shape=(0, 2 * num_anchors, |
| 318 | -1, 0)) |
| 319 | outs.append(cls_pred) |
| 320 | if stride in config.CASCADE_BBOX_STRIDES: |
| 321 | _name = 'face_rpn_bbox_pred_stride%d_cas%d_output' % ( |
| 322 | stride, casid) |
| 323 | bbox_pred = all_layers[_name] |
| 324 | outs.append(bbox_pred) |
| 325 | else: |
| 326 | _name = 'face_rpn_cls_score_stride%d_output' % stride |
| 327 | rpn_cls_score = all_layers[_name] |
| 328 | |
| 329 | # prepare rpn data |
| 330 | rpn_cls_score_reshape = mx.symbol.Reshape( |
| 331 | data=rpn_cls_score, |
| 332 | shape=(0, 2, -1, 0), |
| 333 | name="face_rpn_cls_score_reshape_stride%d" % stride) |
| 334 | |
| 335 | rpn_cls_prob = mx.symbol.SoftmaxActivation( |
| 336 | data=rpn_cls_score_reshape, |
| 337 | mode="channel", |
| 338 | name="face_rpn_cls_prob_stride%d" % stride) |
| 339 | rpn_cls_prob_reshape = mx.symbol.Reshape( |
| 340 | data=rpn_cls_prob, |
no test coverage detected