diff --git a/caffe2fluid/examples/imagenet/infer.py b/caffe2fluid/examples/imagenet/infer.py index 3962d96ba1043ca8b8e4121f294c1fb0c10e928c..6fca82bba82bd34c9be74850a41dfa57fccc7f8a 100644 --- a/caffe2fluid/examples/imagenet/infer.py +++ b/caffe2fluid/examples/imagenet/infer.py @@ -172,7 +172,7 @@ def load_model(exe, place, net_file, net_name, net_weight, debug): def get_shape(fluid, program, name): for var in program.list_vars(): - if var.name == 'data': + if var.type == 'Input': return list(var.shape[1:]) raise ValueError('not found shape for input layer[%s], ' diff --git a/caffe2fluid/examples/imagenet/tools/diff.sh b/caffe2fluid/examples/imagenet/tools/diff.sh index c1756e83b2fa11e2dc212abe7c727f3adc6c6bb0..8a561a821f8d10d2e8537d83908029532d3cde15 100755 --- a/caffe2fluid/examples/imagenet/tools/diff.sh +++ b/caffe2fluid/examples/imagenet/tools/diff.sh @@ -49,7 +49,7 @@ if [[ -z $PYTHON ]];then PYTHON=`which python` fi $PYTHON ../../convert.py \ - $proto_file \ + --npy_path $proto_file \ --caffemodel $caffemodel_file \ --data-output-path $weight_file\ --code-output-path $net_file diff --git a/caffe2fluid/kaffe/custom_layers/reshape.py b/caffe2fluid/kaffe/custom_layers/reshape.py index da82e4d67c7cbb558c223bce528cb23c7feb91c8..b4ec051d7b4f349079f81de874aef9cdf2d18a65 100644 --- a/caffe2fluid/kaffe/custom_layers/reshape.py +++ b/caffe2fluid/kaffe/custom_layers/reshape.py @@ -2,6 +2,7 @@ more info can be found here: http://caffe.berkeleyvision.org/tutorial/layers/reshape.html """ from .register import register +from functools import reduce def import_fluid(): @@ -61,43 +62,6 @@ def reshape_shape(input_sp, shape, axis=0, num_axes=-1): assert len(output_shape) == num_axes_retained + num_new_axes,\ "[Reshape]invalid dims of output shape[%s]" % (str(output_shape)) - inferred_axis = -1 - copy_axes = [] - constant_count = 1 - for i in range(num_new_axes): - top_dim = shape['dim'][i] - if top_dim == 0: - copy_axes.append(i) - copy_axis_index = start_axis + i - output_shape[copy_axis_index] = input_shape[copy_axis_index] - elif top_dim == -1: - assert inferred_axis == -1, "[Reshape]new shape contains multiple -1 dims" - inferred_axis = i - else: - constant_count *= top_dim - - if inferred_axis >= 0: - explicit_count = constant_count - l = input_shape[0:start_axis] - if len(l) > 0: - explicit_count *= count(l) - - l = input_shape[end_axis:] - if len(l) > 0: - explicit_count *= count(l) - - for i in range(len(copy_axes)): - explicit_count *= output_shape[start_axis + copy_axes[i]] - - assert input_count % explicit_count == 0, "[Reshape]botom count[%d] "\ - "must be divisible by product of the specified dimensions[%d] "\ - % (input_count, explicit_count) - output_shape[start_axis + inferred_axis] = input_count / explicit_count - - output_count = count(output_shape) - assert output_count == input_count, "[Reshape]output count[%d] must match input count[%d]" % ( - output_count, input_count) - return output_shape @@ -117,17 +81,18 @@ def reshape_layer(input, name, shape, axis=0, num_axes=-1): fluid = import_fluid() input_shape = list(input.shape) + print(input_shape) + print(shape) if input_shape[0] == -1: - input_shape[0] = 1 + input_shape[0] = 0 output_shape = reshape_shape(input_shape, shape, axis, num_axes) - output_shape[0] = -1 else: output_shape = reshape_shape(input_shape, shape, axis, num_axes) - output = fluid.layers.reshape(input, shape=output_shape, name=name) return output register(kind='Reshape', shape=reshape_shape, layer=reshape_layer) + diff --git a/caffe2fluid/kaffe/paddle/network.py b/caffe2fluid/kaffe/paddle/network.py index 87d1c27a17bc774234b13476dab72a69eb99f820..88eba56d87a306f30eb6b80580ea0034bf70b537 100644 --- a/caffe2fluid/kaffe/paddle/network.py +++ b/caffe2fluid/kaffe/paddle/network.py @@ -103,7 +103,7 @@ class Network(object): place = self.paddle_env['place'] exe = self.paddle_env['exe'] - data_dict = np.load(data_path).item() + data_dict = np.load(data_path, allow_pickle=True).item() for op_name in data_dict: if op_name == 'caffe2fluid_name_trace': self.name_trace = data_dict[op_name] @@ -441,7 +441,7 @@ class Network(object): need_transpose = True if need_transpose: - in_order = range(dims) + in_order = list(range(dims)) in_order.remove(axis) in_order.append(axis) input = fluid.layers.transpose( diff --git a/caffe2fluid/kaffe/shapes.py b/caffe2fluid/kaffe/shapes.py index 4bbdbdebd403f524d0db23e206f0fd394d8e46e4..e3e4e710c8b0c83ef757d4efcf22873d926618c9 100644 --- a/caffe2fluid/kaffe/shapes.py +++ b/caffe2fluid/kaffe/shapes.py @@ -3,6 +3,9 @@ from collections import namedtuple from .errors import KaffeError +Tensor5DShape = namedtuple('Tensor5DShape', + ['batch_size', 'data1', 'daat2', 'data3', 'data4']) + Tensor4DShape = namedtuple('Tensor4DShape', ['batch_size', 'channels', 'height', 'width'])