onnx2tf 1.29.7__py3-none-any.whl → 1.29.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
onnx2tf/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from onnx2tf.onnx2tf import convert, main
2
2
 
3
- __version__ = '1.29.7'
3
+ __version__ = '1.29.9'
onnx2tf/ops/Unsqueeze.py CHANGED
@@ -69,52 +69,58 @@ def make_node(
69
69
  if isinstance(graph_node_input_1, gs.Variable) \
70
70
  and 'nhwc' in tf_layers_dict[graph_node_input_1.name].keys() else False
71
71
 
72
+ input_tensor_shape = None
73
+ tensor_rank = None
72
74
  if input_tensor.shape != tf.TensorShape(None):
73
75
  input_tensor_shape = list(input_tensor.shape)
74
- tensor_rank = len(input_tensor_shape)
75
- elif graph_node_output.shape is not None:
76
+ elif graph_node_output.shape is not None and axes is not None:
76
77
  input_tensor_shape = [
77
78
  dim for idx, dim in enumerate(graph_node_output.shape) if idx not in axes
78
79
  ]
79
80
  input_tensor_shape = [
80
81
  dim if not isinstance(dim, str) else None for dim in input_tensor_shape
81
82
  ]
83
+ if input_tensor_shape is not None:
82
84
  tensor_rank = len(input_tensor_shape)
83
85
 
84
86
  if isinstance(axes, list) or (isinstance(axes, np.ndarray) and len(axes.shape) > 0):
85
- if nhwc:
86
- axes = [
87
- convert_axis(
88
- axis=idx,
89
- tensor_rank=tensor_rank+len(axes),
90
- before_op_output_shape_trans=True,
91
- ) for idx in axes
92
- ]
93
- elif not nhwc and (isinstance(axes, list) and len(axes) == 1 or isinstance(axes, np.ndarray) and len(axes.shape) == 1) and axes[0] == -1:
94
- axes = [
95
- convert_axis(
96
- axis=idx,
97
- tensor_rank=tensor_rank+len(axes),
98
- before_op_output_shape_trans=before_op_output_shape_trans,
99
- ) for idx in axes
100
- ]
87
+ if tensor_rank is not None:
88
+ if nhwc:
89
+ axes = [
90
+ convert_axis(
91
+ axis=idx,
92
+ tensor_rank=tensor_rank+len(axes),
93
+ before_op_output_shape_trans=True,
94
+ ) for idx in axes
95
+ ]
96
+ elif not nhwc and (isinstance(axes, list) and len(axes) == 1 or isinstance(axes, np.ndarray) and len(axes.shape) == 1) and axes[0] == -1:
97
+ axes = [
98
+ convert_axis(
99
+ axis=idx,
100
+ tensor_rank=tensor_rank+len(axes),
101
+ before_op_output_shape_trans=before_op_output_shape_trans,
102
+ ) for idx in axes
103
+ ]
104
+ else:
105
+ axes = [idx for idx in axes]
101
106
  else:
102
- axes = [idx for idx in axes]
107
+ axes = [int(idx) for idx in axes]
103
108
  elif axes is not None and isinstance(axes, np.ndarray) and len(axes.shape) == 0:
104
- if nhwc:
105
- axes = convert_axis(
106
- axis=axes,
107
- tensor_rank=tensor_rank+1,
108
- before_op_output_shape_trans=True,
109
- )
110
- elif not nhwc and (isinstance(axes, list) and len(axes) == 1 or isinstance(axes, np.ndarray) and len(axes.shape) == 1) and axes[0] == -1:
111
- axes = [
112
- convert_axis(
113
- axis=idx,
114
- tensor_rank=tensor_rank+len(axes),
115
- before_op_output_shape_trans=before_op_output_shape_trans,
116
- ) for idx in axes
117
- ]
109
+ if tensor_rank is not None:
110
+ if nhwc:
111
+ axes = convert_axis(
112
+ axis=axes,
113
+ tensor_rank=tensor_rank+1,
114
+ before_op_output_shape_trans=True,
115
+ )
116
+ elif not nhwc and (isinstance(axes, list) and len(axes) == 1 or isinstance(axes, np.ndarray) and len(axes.shape) == 1) and axes[0] == -1:
117
+ axes = [
118
+ convert_axis(
119
+ axis=idx,
120
+ tensor_rank=tensor_rank+len(axes),
121
+ before_op_output_shape_trans=before_op_output_shape_trans,
122
+ ) for idx in axes
123
+ ]
118
124
  axes = list(axes[np.newaxis])
119
125
 
120
126
  if axes is not None and isinstance(axes, list) and len(axes) > 0:
@@ -128,11 +134,13 @@ def make_node(
128
134
  **kwargs,
129
135
  )
130
136
 
131
- new_shape = copy.deepcopy(input_tensor_shape)
132
- for idx in axes:
133
- new_shape.insert(idx, 1)
137
+ new_shape = None
138
+ if input_tensor_shape is not None and axes is not None:
139
+ new_shape = copy.deepcopy(input_tensor_shape)
140
+ for idx in axes:
141
+ new_shape.insert(idx, 1)
134
142
 
135
- new_shape = [dim if dim is not None else -1 for dim in new_shape]
143
+ new_shape = [dim if dim is not None else -1 for dim in new_shape]
136
144
 
137
145
  # Preserving Graph Structure (Dict)
138
146
  tf_layers_dict[graph_node_output.name] = {
@@ -234,6 +242,29 @@ def make_node(
234
242
  tf.identity(input=input_tensor)
235
243
  tf_type = tf.identity
236
244
 
245
+ elif not shape_replaced \
246
+ and new_shape is None:
247
+ axes_list = axes
248
+ if axes_list is None:
249
+ axes_list = []
250
+ elif isinstance(axes_list, np.ndarray):
251
+ axes_list = axes_list.tolist() if axes_list.shape != () else [int(axes_list)]
252
+ elif not isinstance(axes_list, list):
253
+ axes_list = [int(axes_list)]
254
+
255
+ unsqueeze_tensor = input_tensor
256
+ for axis_idx, axis in enumerate(axes_list):
257
+ axis_val = int(axis) if isinstance(axis, (np.integer, np.int64, np.int32)) else axis
258
+ if isinstance(axis_val, int) and axis_val < 0:
259
+ axis_val = tf.rank(unsqueeze_tensor) + axis_val + 1
260
+ unsqueeze_tensor = tf.expand_dims(
261
+ input=unsqueeze_tensor,
262
+ axis=axis_val,
263
+ name=graph_node.name if axis_idx == len(axes_list) - 1 else None,
264
+ )
265
+ tf_layers_dict[graph_node_output.name]['tf_node'] = unsqueeze_tensor
266
+ tf_type = tf.expand_dims
267
+
237
268
  elif not shape_replaced \
238
269
  and nhwc \
239
270
  and len(axes) == 1 \
@@ -247,6 +278,7 @@ def make_node(
247
278
  tf_type = tf.expand_dims
248
279
 
249
280
  elif not shape_replaced \
281
+ and new_shape is not None \
250
282
  and len(new_shape) >= 2 \
251
283
  and len([dim for dim in new_shape if dim is None or dim == -1]) >= 2 \
252
284
  and not isinstance(axes, int) \
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onnx2tf
3
- Version: 1.29.7
3
+ Version: 1.29.9
4
4
  Summary: Self-Created Tools to convert ONNX files (NCHW) to TensorFlow/TFLite/Keras format (NHWC).
5
5
  Home-page: https://github.com/PINTO0309/onnx2tf
6
6
  Author: Katsuya Hyodo
@@ -16,7 +16,8 @@ Requires-Dist: numpy==1.26.4
16
16
  Requires-Dist: onnx==1.19.0
17
17
  Requires-Dist: onnxruntime==1.23.0
18
18
  Requires-Dist: opencv-python==4.11.0.86
19
- Requires-Dist: onnxsim==0.4.30
19
+ Requires-Dist: onnxsim==0.4.36
20
+ Requires-Dist: onnxoptimizer==0.4.2
20
21
  Requires-Dist: ai-edge-litert==2.1.0
21
22
  Requires-Dist: tensorflow==2.19.0
22
23
  Requires-Dist: tf-keras==2.19.0
@@ -306,10 +307,11 @@ Video speed is adjusted approximately 50 times slower than actual speed.
306
307
  - Linux / Windows
307
308
  - onnx==1.19.0
308
309
  - onnxruntime==1.23.0
309
- - onnx-simplifier==0.4.33 or 0.4.30 `(onnx.onnx_cpp2py_export.shape_inference.InferenceError: [ShapeInferenceError] (op_type:Slice, node name: /xxxx/Slice): [ShapeInferenceError] Inferred shape and existing shape differ in rank: (x) vs (y))`
310
+ - onnxsim==0.4.36
311
+ - onnxoptimizer==0.4.2
310
312
  - onnx_graphsurgeon==0.5.8
311
313
  - simple_onnx_processing_tools==1.1.32
312
- - tensorflow==2.19.0, Special bugs: [#436](https://github.com/PINTO0309/onnx2tf/issues/436)
314
+ - tensorflow==2.19.0
313
315
  - tf-keras==2.19.0
314
316
  - ai-edge-litert==1.2.0
315
317
  - psutil==5.9.5
@@ -357,7 +359,7 @@ Video speed is adjusted approximately 50 times slower than actual speed.
357
359
  docker run --rm -it \
358
360
  -v `pwd`:/workdir \
359
361
  -w /workdir \
360
- ghcr.io/pinto0309/onnx2tf:1.29.7
362
+ ghcr.io/pinto0309/onnx2tf:1.29.9
361
363
 
362
364
  or
363
365
 
@@ -365,14 +367,15 @@ Video speed is adjusted approximately 50 times slower than actual speed.
365
367
  docker run --rm -it \
366
368
  -v `pwd`:/workdir \
367
369
  -w /workdir \
368
- docker.io/pinto0309/onnx2tf:1.29.7
370
+ docker.io/pinto0309/onnx2tf:1.29.9
369
371
 
370
372
  or
371
373
 
372
374
  pip install -U onnx==1.19.0 \
373
375
  && pip install -U onnx-graphsurgeon==0.5.8 \
374
376
  && pip install -U onnxruntime==1.23.0 \
375
- && pip install -U onnxsim==0.4.33 \
377
+ && pip install -U onnxsim==0.4.36 \
378
+ && pip install -U onnxoptimizer==0.4.2 \
376
379
  && pip install -U simple_onnx_processing_tools==1.1.32 \
377
380
  && pip install -U sne4onnx>=1.0.13 \
378
381
  && pip install -U sng4onnx>=1.0.4 \
@@ -1,4 +1,4 @@
1
- onnx2tf/__init__.py,sha256=knP_P2W7jk-XqY8ebkyeA4xA5ZC_5WiqL_rZg3pdctY,66
1
+ onnx2tf/__init__.py,sha256=0iOZ-E1Mv5pU4CHm_29h1gNBG_KtKmxjV5sHtV-0DKI,66
2
2
  onnx2tf/__main__.py,sha256=2RSCQ7d4lc6CwD-rlGn9UicPFg-P5du7ZD_yh-kuBEU,57
3
3
  onnx2tf/onnx2tf.py,sha256=wdBA-lgCEu-ZfUAKIUQgLe8hSP8ifE7rS6nWAq6iF6o,151519
4
4
  onnx2tf/ops/Abs.py,sha256=V7btmCG_ZvK_qJovUsguq0ZMJ349mhNQ4FHSgzP_Yuo,4029
@@ -185,7 +185,7 @@ onnx2tf/ops/TopK.py,sha256=f6OG-DcMWneXwSjIkmY935SPyOMD5tMteHnlQHoJwQo,6348
185
185
  onnx2tf/ops/Transpose.py,sha256=GwJFp7zVqodEsv5mGWviuFqeK93uVM7dbRQ1N8Ua1hg,9774
186
186
  onnx2tf/ops/Trilu.py,sha256=uz2TgdErpo9GDp9n4PCe0_koIpNLgBoPCjv3A6VBTl8,4789
187
187
  onnx2tf/ops/Unique.py,sha256=GUuOeTO9px22dHmlAn2SOmRHvBgSXo-SaPWm5rYUtPc,4084
188
- onnx2tf/ops/Unsqueeze.py,sha256=uXZTFJYan_okpVU9jQ3ICNOhrz_jiwaY_R3wxA3UAuI,10749
188
+ onnx2tf/ops/Unsqueeze.py,sha256=UJun_DYfg7aQaHoeAvWlB85oRtDWq2lP7kvb0njcaC0,12219
189
189
  onnx2tf/ops/Upsample.py,sha256=SX3N_wZHD8G5Z0PLcPgX1ZCzOdct-uTzxKeMhhzeBOw,5304
190
190
  onnx2tf/ops/Where.py,sha256=MaCcY9g4mKZQqCgh4xtoylicP-xVu9f4boKiu_q9Ow8,7711
191
191
  onnx2tf/ops/Xor.py,sha256=2ceqxHSI1Wtez_CIh8gFfvcu45Xboqfyp1iy3v2vuIs,4590
@@ -198,9 +198,9 @@ onnx2tf/utils/enums.py,sha256=7c5TqetqB07VjyHoxJHfLgtqBqk9ZRyUF33fPOJR1IM,1649
198
198
  onnx2tf/utils/iterative_json_optimizer.py,sha256=qqeIxWGxrhcCYk8-ebWnblnOkzDCwi-nseipHzHR_bk,10436
199
199
  onnx2tf/utils/json_auto_generator.py,sha256=OC-SfKtUg7zUxaXTAg6kT0ShzIc3ByjDa3FNp173DtA,60302
200
200
  onnx2tf/utils/logging.py,sha256=yUCmPuJ_XiUItM3sZMcaMO24JErkQy7zZwVTYWAuiKg,1982
201
- onnx2tf-1.29.7.dist-info/licenses/LICENSE,sha256=5v_Kxihy8i6mzHVl349ikSREaIdsl9YeUnX1KBDLD2w,1070
202
- onnx2tf-1.29.7.dist-info/licenses/LICENSE_onnx-tensorflow,sha256=gK4GtS9S5YcyINu6uuNNWdo-kBClyEM4MFLFGiNTeRM,11231
203
- onnx2tf-1.29.7.dist-info/METADATA,sha256=uWJ8kHjVfJXkyb9mJVIylYLy_aj6zNOBuRp9Qt6fIDY,153697
204
- onnx2tf-1.29.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
205
- onnx2tf-1.29.7.dist-info/top_level.txt,sha256=WgfPiEy3f6vZ_FOpAIEA2CF3TCx1eYrhGw93Ih6b9Fw,8
206
- onnx2tf-1.29.7.dist-info/RECORD,,
201
+ onnx2tf-1.29.9.dist-info/licenses/LICENSE,sha256=5v_Kxihy8i6mzHVl349ikSREaIdsl9YeUnX1KBDLD2w,1070
202
+ onnx2tf-1.29.9.dist-info/licenses/LICENSE_onnx-tensorflow,sha256=gK4GtS9S5YcyINu6uuNNWdo-kBClyEM4MFLFGiNTeRM,11231
203
+ onnx2tf-1.29.9.dist-info/METADATA,sha256=_Rhg96G54IqDYqigqKQjYlFIzp3SRB2wpRrt03eeZ1w,153504
204
+ onnx2tf-1.29.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
205
+ onnx2tf-1.29.9.dist-info/top_level.txt,sha256=WgfPiEy3f6vZ_FOpAIEA2CF3TCx1eYrhGw93Ih6b9Fw,8
206
+ onnx2tf-1.29.9.dist-info/RECORD,,