@@ -2112,20 +2112,29 @@ def version_10(cls, ctx, node, **kwargs):
2112
2112
axes = axes .tolist ()
2113
2113
len_axes = len (axes )
2114
2114
2115
+ input_rank = ctx .get_rank (node .input [0 ])
2116
+ utils .make_sure (input_rank is not None , "rank of {} is unknown" .format (node .input [0 ]))
2117
+ needs_squeeze = False
2118
+ if input_rank == 1 and len_axes != 0 :
2119
+ # ReverseSequence node requires rank >= 2
2120
+ utils .make_sure (axes in [[- 1 ], [0 ]], "Invalid value %s for axes of ReverseV2 of 1d tensor" , axes )
2121
+ axes = [1 ]
2122
+ new_inp = GraphBuilder (ctx ).make_unsqueeze ({'data' : node .input [0 ], 'axes' : [0 ]})
2123
+ ctx .replace_input (node , node .input [0 ], new_inp , 0 )
2124
+ input_rank = 2
2125
+ needs_squeeze = True
2126
+
2115
2127
# Store input and output parameters of the ReverseV2 node.
2116
2128
rv2_in_names = [node .input [0 ]]
2117
2129
2118
- input_shape = ctx .get_shape (node .input [0 ])
2119
- input_rank = len (input_shape )
2120
2130
input_shape_node = ctx .make_node ("Shape" , [node .input [0 ]], op_name_scope = node .name )
2121
2131
2122
- # Make sure input shape is not None
2123
- utils .make_sure (input_shape is not None , "shape of {} is None" .format (node .input [0 ]))
2124
-
2125
2132
rv2_node_name = node .name
2126
2133
# ReverseV2 has a single output.
2127
2134
rv2_output_dtypes = node .output_dtypes
2128
2135
rv2_output_shapes = node .output_shapes
2136
+ if needs_squeeze and rv2_output_shapes is not None :
2137
+ rv2_output_shapes [0 ] = [1 ] + rv2_output_shapes [0 ]
2129
2138
2130
2139
# Remove ReverseV2 node from graph.
2131
2140
ctx .remove_node (rv2_node_name )
@@ -2243,6 +2252,10 @@ def version_10(cls, ctx, node, **kwargs):
2243
2252
attr = {"perm" : curr_perm }
2244
2253
)
2245
2254
2255
+ if needs_squeeze :
2256
+ sq_node = GraphBuilder (ctx ).make_squeeze ({"data" : node .output [0 ], "axes" : [0 ]}, return_node = True )
2257
+ ctx .insert_node_on_output (sq_node )
2258
+
2246
2259
2247
2260
@tf_op ("Unique" , onnx_op = "Unique" )
2248
2261
class Unique :
0 commit comments