Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvTranspose bias tensor dimensions are not aligned with spec #297

Closed
talc23 opened this issue Oct 21, 2018 · 5 comments
Closed

ConvTranspose bias tensor dimensions are not aligned with spec #297

talc23 opened this issue Oct 21, 2018 · 5 comments

Comments

@talc23
Copy link
Contributor

talc23 commented Oct 21, 2018

Describe the bug

according to spec B.shape==[C] where C is the input's number of channels.
however model building is failing unless B.shape==[M] where M is the output's number of channels.

I think that maybe B should be accumulated and then broadcasted across Conv2DBackpropInput output. right now B is added as is to Conv2DBackpropInput output

To Reproduce

import onnx.helper as helper
from onnx import TensorProto
import numpy as np
from onnx_tf.backend import prepare

N=1
Cx=2
Hx=3
Wx=3
xDims = [N, Cx, Hx, Wx]

Cy=3
Hy=5
Wy=5
yDims = [N, Cy, Hy, Wy]

Ww=3
Hw=3
wDims = [Cx, Cy, Hw, Ww]

bDims = [Cx]

graph_proto = helper.make_graph(
[
helper.make_node("ConvTranspose", ["X", "W", "B"], ["Y"], output_shape=yDims,
pads=[1,1,1,1], strides=[2,2]),
],
"ConvTranspose1",
[
helper.make_tensor_value_info('X' , TensorProto.FLOAT, xDims),
helper.make_tensor_value_info('W' , TensorProto.FLOAT, wDims),
helper.make_tensor_value_info('B' , TensorProto.FLOAT, bDims),
],
[
helper.make_tensor_value_info('Y', TensorProto.FLOAT, yDims),
]
)
#graph_proto.initializer.extend([_sample_float_tensor()])
#graph_proto.initializer[0].name = 'W1'
model = helper.make_model(graph_proto)
f = open('convtranspose_test_model.pb', "wb")
f.write(model.SerializeToString())
f.close()

np.random.seed(0)
#create the input and output file:
#input = np.arange(1, 4, dtype=np.float32);
x = None
w = None
b = None

varType = 'float'
if varType == 'float':
x = np.random.random(np.prod(xDims)).reshape(xDims)
w = np.random.random(np.prod(wDims)).reshape(wDims)
b = np.random.random(np.prod(bDims)).reshape(bDims)
elif varType == 'int':
x = np.random.randint(-5,5,np.prod(xDims)).reshape(xDims)
w = np.random.randint(-5,5,np.prod(wDims)).reshape(wDims)
b = np.random.randint(-5,5,np.prod(bDims)).reshape(bDims)
elif varType == 'ones':
x = np.ones(np.prod(xDims)).reshape(xDims)
w = np.ones(np.prod(wDims)).reshape(wDims)
w[:,1,:,:]*=2
b = np.zeros(np.prod(bDims)).reshape(bDims)

np.savez('convtranspose_input_data', X=x, W=w, B=b)
#np.savez('convtranspose_output_data', outputs=output)

print("\ngraph proto:\n")
print(graph_proto)

tf_rep = prepare(model) # Import the ONNX model to Tensorflow
y = tf_rep.run([x,w,b])

failure:
File "c:\Users\tchercke\Documents\Repos\aipg_inference-dl\modules\framework_importer\scripts\simple_convtranspose_model_gen.py", line 84, in
tf_rep = prepare(model) # Import the ONNX model to Tensorflow
ValueError: Dimensions must be equal, but are 3 and 2 for 'Add' (op: 'Add') with input shapes: [1,5,5,3], [2].

Python, ONNX, ONNX-TF, Tensorflow version

This section can be obtained by running get_version.py from util folder.
Python version:
3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:27:44) [MSC v.1900 64 bit (AMD64)]
ONNX version:
1.3.0
ONNX-TF version:
1.2.0
Tensorflow version:
1.11.0

@fumihwh
Copy link
Collaborator

fumihwh commented Oct 21, 2018

@talc23
Copy link
Contributor Author

talc23 commented Oct 21, 2018

I'll open an issue in ONNX repo.

@fumihwh
Copy link
Collaborator

fumihwh commented Oct 21, 2018

@talc23
Already opened.

@talc23
Copy link
Contributor Author

talc23 commented Oct 21, 2018

I'll close mine

@fumihwh
Copy link
Collaborator

fumihwh commented Nov 2, 2018

@talc23
onnx/onnx#1566
FYI, merged.

@fumihwh fumihwh closed this as completed Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants