diff --git a/ppdet/modeling/heads/roi_extractor.py b/ppdet/modeling/heads/roi_extractor.py index 260b375d953aeb2e62f2da57c9c2def430136b43..19ce3df826f06f52f01a34a65117609a35162555 100644 --- a/ppdet/modeling/heads/roi_extractor.py +++ b/ppdet/modeling/heads/roi_extractor.py @@ -87,13 +87,23 @@ class RoIAlign(object): offset = 2 k_min = self.start_level + offset k_max = self.end_level + offset - rois_dist, restore_index, rois_num_dist = ops.distribute_fpn_proposals( - roi, - k_min, - k_max, - self.canconical_level, - self.canonical_size, - rois_num=rois_num) + if hasattr(paddle.vision.ops, "distribute_fpn_proposals"): + rois_dist, restore_index, rois_num_dist = paddle.vision.ops.distribute_fpn_proposals( + roi, + k_min, + k_max, + self.canconical_level, + self.canonical_size, + rois_num=rois_num) + else: + ops.distribute_fpn_proposals( + roi, + k_min, + k_max, + self.canconical_level, + self.canonical_size, + rois_num=rois_num) + rois_feat_list = [] for lvl in range(self.start_level, self.end_level + 1): roi_feat = paddle.vision.ops.roi_align( diff --git a/ppdet/modeling/ops.py b/ppdet/modeling/ops.py index 567c26d7233e561118e22ca3a8e7d74f7b7cf686..025b60050237824673b6070a3d910a1895904270 100644 --- a/ppdet/modeling/ops.py +++ b/ppdet/modeling/ops.py @@ -17,7 +17,10 @@ import paddle.nn.functional as F import paddle.nn as nn from paddle import ParamAttr from paddle.regularizer import L2Decay -from paddle import _C_ops +try: + import paddle._legacy_C_ops as C_ops +except: + import paddle._C_ops as C_ops from paddle import in_dynamic_mode from paddle.common_ops_import import Variable, LayerHelper, check_variable_and_dtype, check_type, check_dtype @@ -198,8 +201,9 @@ def distribute_fpn_proposals(fpn_rois, attrs = ('min_level', min_level, 'max_level', max_level, 'refer_level', refer_level, 'refer_scale', refer_scale, 'pixel_offset', pixel_offset) - multi_rois, restore_ind, rois_num_per_level = _C_ops.distribute_fpn_proposals( + multi_rois, restore_ind, rois_num_per_level = C_ops.distribute_fpn_proposals( fpn_rois, rois_num, num_lvl, num_lvl, *attrs) + return multi_rois, restore_ind, rois_num_per_level else: @@ -353,7 +357,7 @@ def prior_box(input, 'min_max_aspect_ratios_order', min_max_aspect_ratios_order) if cur_max_sizes is not None: attrs += ('max_sizes', cur_max_sizes) - box, var = _C_ops.prior_box(input, image, *attrs) + box, var = C_ops.prior_box(input, image, *attrs) return box, var else: attrs = { @@ -496,8 +500,8 @@ def multiclass_nms(bboxes, score_threshold, 'nms_top_k', nms_top_k, 'nms_threshold', nms_threshold, 'keep_top_k', keep_top_k, 'nms_eta', nms_eta, 'normalized', normalized) - output, index, nms_rois_num = _C_ops.multiclass_nms3(bboxes, scores, - rois_num, *attrs) + output, index, nms_rois_num = C_ops.multiclass_nms3(bboxes, scores, + rois_num, *attrs) if not return_index: index = None return output, nms_rois_num, index @@ -638,7 +642,7 @@ def matrix_nms(bboxes, nms_top_k, 'gaussian_sigma', gaussian_sigma, 'use_gaussian', use_gaussian, 'keep_top_k', keep_top_k, 'normalized', normalized) - out, index, rois_num = _C_ops.matrix_nms(bboxes, scores, *attrs) + out, index, rois_num = C_ops.matrix_nms(bboxes, scores, *attrs) if not return_index: index = None if not return_rois_num: @@ -791,12 +795,12 @@ def box_coder(prior_box, if in_dynamic_mode(): if isinstance(prior_box_var, Variable): - output_box = _C_ops.box_coder( + output_box = C_ops.box_coder( prior_box, prior_box_var, target_box, "code_type", code_type, "box_normalized", box_normalized, "axis", axis) elif isinstance(prior_box_var, list): - output_box = _C_ops.box_coder( + output_box = C_ops.box_coder( prior_box, None, target_box, "code_type", code_type, "box_normalized", box_normalized, "axis", axis, "variance", prior_box_var) @@ -919,7 +923,7 @@ def generate_proposals(scores, attrs = ('pre_nms_topN', pre_nms_top_n, 'post_nms_topN', post_nms_top_n, 'nms_thresh', nms_thresh, 'min_size', min_size, 'eta', eta, 'pixel_offset', pixel_offset) - rpn_rois, rpn_roi_probs, rpn_rois_num = _C_ops.generate_proposals_v2( + rpn_rois, rpn_roi_probs, rpn_rois_num = C_ops.generate_proposals_v2( scores, bbox_deltas, im_shape, anchors, variances, *attrs) if not return_rois_num: rpn_rois_num = None diff --git a/ppdet/modeling/proposal_generator/proposal_generator.py b/ppdet/modeling/proposal_generator/proposal_generator.py index 1fcb8b1e2de963e9867249bbb6bc2f524e07d1d2..6c722c8cf0872140b77acb2ff9bb1af352cb66e7 100644 --- a/ppdet/modeling/proposal_generator/proposal_generator.py +++ b/ppdet/modeling/proposal_generator/proposal_generator.py @@ -62,16 +62,31 @@ class ProposalGenerator(object): top_n = self.pre_nms_top_n if self.topk_after_collect else self.post_nms_top_n variances = paddle.ones_like(anchors) - rpn_rois, rpn_rois_prob, rpn_rois_num = ops.generate_proposals( - scores, - bbox_deltas, - im_shape, - anchors, - variances, - pre_nms_top_n=self.pre_nms_top_n, - post_nms_top_n=top_n, - nms_thresh=self.nms_thresh, - min_size=self.min_size, - eta=self.eta, - return_rois_num=True) + if hasattr(paddle.vision.ops, "generate_proposals"): + rpn_rois, rpn_rois_prob, rpn_rois_num = paddle.vision.ops.generate_proposals( + scores, + bbox_deltas, + im_shape, + anchors, + variances, + pre_nms_top_n=self.pre_nms_top_n, + post_nms_top_n=top_n, + nms_thresh=self.nms_thresh, + min_size=self.min_size, + eta=self.eta, + return_rois_num=True) + else: + rpn_rois, rpn_rois_prob, rpn_rois_num = ops.generate_proposals( + scores, + bbox_deltas, + im_shape, + anchors, + variances, + pre_nms_top_n=self.pre_nms_top_n, + post_nms_top_n=top_n, + nms_thresh=self.nms_thresh, + min_size=self.min_size, + eta=self.eta, + return_rois_num=True) + return rpn_rois, rpn_rois_prob, rpn_rois_num, self.post_nms_top_n diff --git a/ppdet/utils/check.py b/ppdet/utils/check.py index f51a517a1d4e832a5810f63fab7031043a38e661..8909aac55aec882bda65e6c83ebd1ae8e29cef9f 100644 --- a/ppdet/utils/check.py +++ b/ppdet/utils/check.py @@ -101,18 +101,9 @@ def check_version(version='2.2'): paddle_version.rc ] - # Paddledet develop version is only used on Paddle develop - if version_installed == ['0', '0', '0', '0'] and version != 'develop': - raise Exception( - "PaddlePaddle version {} or higher is required, and develop version is only used for PaddleDetection develop version!". - format(version)) - if version_installed == ['0', '0', '0', '0']: return - if version == 'develop': - raise Exception("PaddlePaddle develop version is required!") - version_split = version.split('.') length = min(len(version_installed), len(version_split))