Modifying Faster R-CNN Prototxt
Do not directly copy the code samples in this section to your network model. Adjust the parameters to suit your use case. For example, the bottom and top parameters must match those in the corresponding network model, and the sequence of the bottom and top parameters is fixed.
The following uses the Faster R-CNN ResNet-34 model as an example.
- Modify the Proposal operator.
The operator has three inputs and two outputs as described in Supported Caffe Operators. Change the type argument of the original proposal operator to that defined in the caffe.proto file and add the actual_rois_num output node. Add attribute description by referring to the attribute definition in the caffe.proto file. Figure 1 shows the .prototxt file before and after modification for adapting to the Ascend AI Processor.A code example is as follows.
layer { name: "faster_rcnn_proposal" type: "Proposal" //Operator type bottom: "rpn_cls_prob_reshape" bottom: "rpn_bbox_pred" bottom: "im_info" top: "rois" top: "actual_rois_num" // Added operator output proposal_param { feat_stride: 16 base_size: 16 min_size: 16 pre_nms_topn: 3000 post_nms_topn: 304 iou_threshold: 0.7 output_actual_rois_num: true } }For details about the parameters, see Supported Caffe Operators.
- Add an FSRDetectionOutput operator to the output layer to output the final detection result.
If your network is Faster R-CNN, add a postprocessing layer FSRDetectionOutput to the end of the original .prototxt file by referring to List of Custom Operators. The FSRDetectionOutput operator has five inputs and two outputs as described in Supported Caffe Operators. Define the data types and attributes of the operator accordingly.
A code example is as follows.
layer { name: "FSRDetectionOutput_1" type: "FSRDetectionOutput" bottom: "rois" bottom: "bbox_pred" bottom: "cls_prob" bottom: "im_info" bottom: "actual_rois_num" top: "actual_bbox_num1" top: "box1" fsrdetectionoutput_param { num_classes:3 score_threshold:0.0 iou_threshold:0.7 batch_rois:1 } }For details about the parameters, see Supported Caffe Operators.
