Пример #1
0
def gen_cost(outputs, gts, loss, params):
    #the cost of flow is equivalent with the evaluation EPE
    cost = []
    if 'flow' in loss:
        cost_flow = cost_layers.ns_ele_l2_cost(input=outputs['flow'],
                                               label=gts['flow_gt'],
                                               weight=gts['weight'],
                                               height=params['size'][0],
                                               width=params['size'][1],
                                               num_channel=2)
        cost.append(cost_flow)

    if 'depth' in loss:
        # we set the
        depth_gt = pd.layer.mixed(input=[pd.layer.identity_projection(
                                         input=gts['depth_gt'])],
                                  act=pd.activation.Inv())
        cost_depth = cost_layers.relative_l1(input=outputs['depth'],
                                             label=depth_gt,
                                             weight=gts['weight'],
                                             height=params['size'][0],
                                             width=params['size'][1])
        cost.append(cost_depth)

    if 'normal' in loss:
        cost_normal = cost_layers.inner_product_cost(input=outputs['normal'],
                                                     label=gts['normal_gt'],
                                                     weight=gts['weight'],
                                                     height=params['size'][0],
                                                     width=params['size'][1],
                                                     num_channel=3,
                                                     is_angle=True)
        cost.append(cost_normal)

        return  cost
Пример #2
0
def gen_cost(outputs, gts, loss, params):
    cost = []
    stage = params['stage']

    if 'depth' in loss:
        cost_depth = cost_layers.ele_norm_cost(input=outputs['depth_inv'],
                                         label=gts['depth_gt'],
                                         weight=gts['weight'],
                                         height=params['size_stage'][1][0],
                                         width=params['size_stage'][1][1],
                                         num_channel=1,
                                         cost_type='l1')
        cost.append(cost_depth)


    if 'normal' in loss:
        height, width = params['size_stage'][1]
        normal = util_layers.norm(outputs['normal'], height, width, 3)
        label = paddle.layer.bilinear_interp(input=gts['normal_gt'],
            out_size_x=width, out_size_y=height)
        label = util_layers.norm(label, height, width, 3)
        cost_normal = cost_layers.ns_ele_l2_cost(input=normal,
                                         label=label,
                                         weight=gts['weight'],
                                         height=params['size_stage'][1][0],
                                         width=params['size_stage'][1][1],
                                         num_channel=3)
        # cost_normal = cost_layers.inner_product_cost(input=outputs['normal'],
        #                                  label=gts['normal'],
        #                                  weight=gts['weight'],
        #                                  height=params['size_stage'][1][0],
        #                                  width=params['size_stage'][1][1],
        #                                  num_channel=3)
        cost.append(cost_normal)


    if 'trans' in loss:
        cost_rotation = cost_layers.inner_product_cost(
            input=outputs['rotation'],
            label=gts['rotation'],
            weight=None,
            height=1, width=1, num_channel=3)
        cost_translation = cost_layers.ele_norm_cost(
            input=outputs['translation'],
            label=gts['translation'],
            weight=None,
            height=1, width=1, num_channel=3, cost_type='l1')
        cost.append(cost_rotation)
        cost.append(cost_translation)

    return  cost
Пример #3
0
def test_ns_l2_cost(argv):
    flow_np = np.array([1, 2, 2, 2, 1, 2, 4, 4, 4, 2, 2, 4, 4, 4, 2, 2],
                       dtype=np.float32)
    flow_gt_np = np.array([1, 2, 2, 2, 1, 2, 4, 4, 4, 2, 2, 4, 4, 4, 2, 2],
                          dtype=np.float32)
    flow_gt_np = flow_gt_np + 1.0

    height = 2
    width = 4
    channel = 2

    weight_np = np.ones((height, width), dtype=np.float32).flatten()
    flow = pd.layer.data(name="flow",
                         type=pd.data_type.dense_vector(2 * height * width),
                         height=height,
                         width=width)
    flow_gt = pd.layer.data(name="flow_gt",
                            type=pd.data_type.dense_vector(2 * height * width),
                            height=height,
                            width=width)
    weight = pd.layer.data(name="weight",
                           type=pd.data_type.dense_vector(height * width),
                           height=height,
                           width=width)

    # cost = cost_layers.math_op(input=flow, act=pd.activation.Sqrt())
    cost = cost_layers.ns_ele_l2_cost(input=flow,
                                      label=flow_gt,
                                      weight=weight,
                                      height=height,
                                      width=width,
                                      num_channel=channel)

    parameters, topo = pd.parameters.create(cost)
    cost = pd.infer(output=cost,
                    parameters=parameters,
                    input=[(flow_np, flow_gt_np, weight_np)],
                    feeding={
                        'flow': 0,
                        'flow_gt': 1,
                        'weight': 2
                    })

    print cost.shape, cost