提交 9a8cd211 编写于 作者: S SunAhong1993

fix the bug of load numpy and fix diff.sh, reshape.py

上级 e3413f73
......@@ -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], '
......
......@@ -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
......
......@@ -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)
......@@ -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(
......
......@@ -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'])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册