def _add_roi_keypoint_head( model, add_roi_keypoint_head_func, blob_in, dim_in, spatial_scale_in ): """Add a keypoint prediction head to the model.""" # Capture model graph before adding the mask head bbox_net = copy.deepcopy(model.net.Proto()) # Add the keypoint head blob_keypoint_head, dim_keypoint_head = add_roi_keypoint_head_func( model, blob_in, dim_in, spatial_scale_in ) # Add the keypoint output blob_keypoint = keypoint_rcnn_heads.add_keypoint_outputs( model, blob_keypoint_head, dim_keypoint_head ) if not model.train: # == inference # Inference uses a cascade of box predictions, then keypoint predictions # This requires separate nets for box and keypoint prediction. # So we extract the keypoint prediction net, store it as its own # network, then restore model.net to be the bbox-only network model.keypoint_net, keypoint_blob_out = c2_utils.SuffixNet( 'keypoint_net', model.net, len(bbox_net.op), blob_keypoint ) model.net._net = bbox_net loss_gradients = None else: loss_gradients = keypoint_rcnn_heads.add_keypoint_losses(model) return loss_gradients