From 2c41c5ce51f81657cf5ec2c0ec2ff27e98aa160b Mon Sep 17 00:00:00 2001 From: SunAhong Date: Tue, 2 Jul 2019 16:59:45 +0800 Subject: [PATCH] fix the flatten and detection --- caffe2fluid/kaffe/custom_layers/detection_out.py | 4 ++-- caffe2fluid/kaffe/custom_layers/flatten.py | 7 ++++--- caffe2fluid/kaffe/custom_layers/reshape.py | 4 ---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/caffe2fluid/kaffe/custom_layers/detection_out.py b/caffe2fluid/kaffe/custom_layers/detection_out.py index ff79e26..54e0f68 100644 --- a/caffe2fluid/kaffe/custom_layers/detection_out.py +++ b/caffe2fluid/kaffe/custom_layers/detection_out.py @@ -49,13 +49,13 @@ def detectionoutput_layer(inputs, pbv = fluid.layers.reshape(x=pbv, shape=[-1, 4]) mbox_loc = inputs[0] mbox_loc = fluid.layers.reshape( - x=mbox_loc, shape=[-1, mbox_conf_flatten.shape[1], 4]) + x=mbox_loc, shape=[0, mbox_conf_flatten.shape[1], 4]) default = {"nms_threshold": 0.3, "top_k": 10, "eta": 1.0} fields = ['eta', 'top_k', 'nms_threshold'] for f in default.keys(): - if not nms_param.has_key(f): + if f not in nms_param: nms_param[f] = default[f] nmsed_outs = fluid.layers.detection_output( diff --git a/caffe2fluid/kaffe/custom_layers/flatten.py b/caffe2fluid/kaffe/custom_layers/flatten.py index ebb9771..271cc99 100644 --- a/caffe2fluid/kaffe/custom_layers/flatten.py +++ b/caffe2fluid/kaffe/custom_layers/flatten.py @@ -2,7 +2,7 @@ more info can be found here: http://caffe.berkeleyvision.org/tutorial/layers/flatten.html """ from .register import register - +from functools import reduce def flatten_shape(input_shape, axis=1, end_axis=-1): """ calculate the output shape of this layer using input shape @@ -29,6 +29,8 @@ def flatten_shape(input_shape, axis=1, end_axis=-1): % (start_axis, end_axis) output_shape = input_shape[0:start_axis] flat_sz = reduce(lambda a, b: a * b, input_shape[start_axis:end_axis]) + if flat_sz < 0: + flat_sz = -1 output_shape += [flat_sz] output_shape += input_shape[end_axis:-1] @@ -52,9 +54,8 @@ def flatten_layer(input, name, axis=1, end_axis=-1): input_shape = list(input.shape) if input_shape[0] == -1: - input_shape[0] = 1 + input_shape[0] = 0 output_shape = flatten_shape(input_shape, axis=axis, end_axis=end_axis) - output_shape[0] = -1 else: output_shape = flatten_shape(input_shape, axis=axis, end_axis=end_axis) diff --git a/caffe2fluid/kaffe/custom_layers/reshape.py b/caffe2fluid/kaffe/custom_layers/reshape.py index b4ec051..fc2da27 100644 --- a/caffe2fluid/kaffe/custom_layers/reshape.py +++ b/caffe2fluid/kaffe/custom_layers/reshape.py @@ -79,11 +79,7 @@ def reshape_layer(input, name, shape, axis=0, num_axes=-1): output (variable): output variable for this layer """ fluid = import_fluid() - input_shape = list(input.shape) - print(input_shape) - print(shape) - if input_shape[0] == -1: input_shape[0] = 0 output_shape = reshape_shape(input_shape, shape, axis, num_axes) -- GitLab