Skip to content
Snippets Groups Projects
Commit e55cc05e authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[QONNX] use conv output shape for conv layer conversion

parent bc8e3610
No related branches found
No related tags found
No related merge requests found
...@@ -126,10 +126,20 @@ class FoldQuantWeights(Transformation): ...@@ -126,10 +126,20 @@ class FoldQuantWeights(Transformation):
model.set_tensor_datatype(node_out, new_dtype) model.set_tensor_datatype(node_out, new_dtype)
# Reshape scale for Conv if required # Reshape scale for Conv if required
target_output_shape = model.get_tensor_shape(
target_node.output[0]
)
if target_node.op_type == "Conv" and len(scale.shape) > 0: if target_node.op_type == "Conv" and len(scale.shape) > 0:
bias_shape = [1] * len(scale.shape) conv_out_shape = [1] * len(target_output_shape)
bias_shape[1] = -1 # only support per-output channel scaling
scale = scale.reshape(bias_shape) # (i.e. all scale shape elems besides 0th must be 1s)
if len(scale.shape) > 1:
assert (
np.prod(scale.shape[1:]) == 1
), "Can't fold scale beyond per-out-channel granularity"
# collect all scaling in channels dim (since we constrain)
conv_out_shape[1] = -1
scale = scale.reshape(conv_out_shape)
if scale.shape == (1,): if scale.shape == (1,):
scale = scale[0] scale = scale[0]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment