Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tf2onnx/onnx_opset/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def version_6(cls, ctx, node, **kwargs):
reduce_dim = [reduce_dim]

if ctx.opset < 11:
inp_rank = ctx.get_rank(node.input[0])
if inp_rank is not None:
reduce_dim = [d + inp_rank if d < 0 else d for d in reduce_dim]
utils.make_sure(all(i >= 0 for i in reduce_dim), "negative reduce axis is not supported in onnx for now")

cast = ctx.make_node(op_type="Cast", inputs=[node.input[0]], attr={"to": onnx_pb.TensorProto.FLOAT})
Expand Down
3 changes: 2 additions & 1 deletion tf2onnx/onnx_opset/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ def version_1(cls, ctx, node, **kwargs):
node = GraphBuilder(ctx).make_slice(
kwargs, name=node.name, dtypes=out_dtypes, shapes=out_shapes, return_node=True)
else:
node = ctx.make_node("Identity", [node.input[0]], name=node.name, dtypes=out_dtypes, shapes=out_shapes)
node = ctx.make_node("Identity", [node.input[0]], name=node.name, outputs=node.output,
dtypes=out_dtypes, shapes=out_shapes)
nodes = [node]
if needs_squeeze:
# insert_new_node_on_output(self, op_type, output_name=None, name=None, inputs=None, domain=None, **kwargs)
Expand Down
10 changes: 5 additions & 5 deletions tf2onnx/rewriter/dropout_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def rewrite_dropout(g, ops):
ratio = input3.get_tensor_value()

if input2.inputs[0].is_scalar():
data = input2.inputs[1]
data_output = input2.input[1]
scaling_constant = input2.inputs[0].get_tensor_value()
elif input2.inputs[1].is_scalar():
data = input2.inputs[0]
data_output = input2.input[0]
scaling_constant = input2.inputs[1].get_tensor_value()
else:
logger.warning("Could not find scaling constant for dropout pattern rooted at %s. "
Expand All @@ -89,12 +89,12 @@ def rewrite_dropout(g, ops):
out_name = utils.port_name(op_name)
new_node = g.make_node(
"Dropout",
inputs=[data.output[0]],
inputs=[data_output],
outputs=[out_name],
name=op_name,
attr={"ratio": ratio},
shapes=[g.get_shape(data.output[0])],
dtypes=[g.get_dtype(data.output[0])]
shapes=[g.get_shape(data_output)],
dtypes=[g.get_dtype(data_output)]
)
g.replace_all_inputs(outputs.output[0], new_node.output[0], ops=ops)
for n in nodes_to_remove:
Expand Down
3 changes: 2 additions & 1 deletion tf2onnx/rewriter/random_uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def create_onnx_random_uniform_op(g, tmax, tmin, ru_op, output, to_delete):
dtype = g.get_dtype(output.output[0])
op_name = utils.make_name("RandomUniform")
shape_node = ru_op.inputs[0]
shape_node_output = ru_op.input[0]
shape = g.get_shape(output.output[0])
if shape_node.is_const():
# if the tensorflow input (aka the shape) is const we can use the RandomUniform op
Expand Down Expand Up @@ -103,7 +104,7 @@ def create_onnx_random_uniform_op(g, tmax, tmin, ru_op, output, to_delete):
to_delete.remove(shape_node)
# create a fill op with the shape of the value of the input tensor
zero = g.make_const(utils.make_name("zero"), np.zeros((), dtype=np.float32))
fill_node = g.make_node("Fill", inputs=[shape_node.output[0], zero.name],
fill_node = g.make_node("Fill", inputs=[shape_node_output, zero.name],
shapes=[shape], dtypes=[dtype])
func, _ = handler.tf_op.find_effective_op("Fill")
func(g, fill_node)
Expand Down