detectionoutput.py 1.9 KB
Newer Older
S
SunAhong1993 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
# Copyright (c) 2020  PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import paddle
import paddle.fluid as fluid

def detectionoutput(x0, 
                     x1, 
                     x2, 
                     nms_threshold, 
                     nms_top_k, 
                     keep_top_k, 
                     nms_eta, 
                     score_threshold, 
                     background_label):
    detection_output_layer_attrs = {
            "background_label": background_label,
            "nms_threshold": nms_threshold,
            "nms_top_k": nms_top_k,
            "keep_top_k": keep_top_k,
            "score_threshold": score_threshold,
            "nms_eta": nms_eta}
    priorbox_list = paddle.split(x2, num_or_sections=2, axis=1)
    pb = priorbox_list[0]
    pbv = priorbox_list[1]
    pb = paddle.reshape(x=pb, shape=[-1, 4])
    pbv = paddle.reshape(x=pbv, shape=[-1, 4])
    pb_dim = fluid.layers.shape(pb)[0]
    loc = paddle.reshape(x0, shape=[-1, pb_dim, 4])
    conf_flatten = paddle.reshape(x1, shape=[0, pb_dim, -1])
    out = fluid.layers.detection_output(loc=loc, 
                                        scores=conf_flatten,
                                        prior_box=pb, 
                                        prior_box_var=pbv,
                                        **detection_output_layer_attrs)
    return out