priorbox.py 1.6 KB
Newer Older
S
SunAhong1993 已提交
1 2 3 4 5
from .register import register
from x2paddle.core.util import *


def priorbox_shape(input_shape, max_size=None, aspect_ratio=None):
6
    fc_shape = input_shape[0]
S
SunAhong1993 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20
    N = 1
    if not max_size == None:
        N += 1
    if not aspect_ratio == None:
        N += 2 * len(aspect_ratio)
    N_bbx = fc_shape[2] * fc_shape[3] * N
    output_shape = [1, 2, 4 * N_bbx]
    return [output_shape]


def priorbox_layer(inputs,
                   step=0.0,
                   offset=0.5,
                   min_size=None,
21
                   max_size=[],
S
SunAhong1993 已提交
22 23 24 25 26 27
                   aspect_ratio=[1.0],
                   flip=False,
                   clip=False,
                   variance=[0.1, 0.1, 0.2, 0.2],
                   input_shape=None,
                   name=None):
28 29
    input = inputs[0]
    image = inputs[1]
S
SunAhong1993 已提交
30 31
    steps = tuple(step) if type(step) is list or type(step) is tuple else (step,
                                                                           step)
32

J
jiangjiajun 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45
    box, variance_ = fluid.layers.prior_box(
        input,
        image,
        min_sizes=min_size,
        max_sizes=max_size,
        aspect_ratios=aspect_ratio,
        variance=variance,
        flip=flip,
        clip=clip,
        steps=steps,
        offset=offset,
        name=name,
        min_max_aspect_ratios_order=True)
S
SunAhong1993 已提交
46 47 48 49 50 51 52 53 54 55 56
    box = fluid.layers.reshape(box, [1, 1, -1])
    variance_ = fluid.layers.reshape(variance_, [1, 1, -1])
    out = fluid.layers.concat([box, variance_], axis=1)
    return out


def priorbox_weights(name, data=None):
    weights_name = []
    return weights_name


J
jiangjiajun 已提交
57 58 59 60 61
register(
    kind='PriorBox',
    shape=priorbox_shape,
    layer=priorbox_layer,
    weights=priorbox_weights)