onnx2tf 1.29.22__py3-none-any.whl → 1.29.23__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.22'
3
+ __version__ = '1.29.23'
onnx2tf/ops/PRelu.py CHANGED
@@ -124,22 +124,55 @@ def make_node(
124
124
  tf_layers_dict[graph_node_output.name].pop('nhwc')
125
125
 
126
126
  # Generation of TF OP
127
- if replace_prelu_to_pseudo_prelu:
128
- pos = tf.nn.relu(input_tensor)
129
- neg = (input_tensor - abs(input_tensor)) * (slope * 0.5)
130
- tf_layers_dict[graph_node_output.name]['tf_node'] = pos + neg
131
- else:
127
+ shared_axes = None
128
+ input_shape = input_tensor.shape
129
+ slope_shape = slope.shape if hasattr(slope, 'shape') else None
130
+ if input_shape is not None and slope_shape is not None:
131
+ input_rank = len(input_shape)
132
+ if len(slope_shape) == input_rank - 1:
133
+ shared_axes = [
134
+ i + 1 for i, dim in enumerate(slope_shape)
135
+ if dim is not None and dim == 1
136
+ ]
137
+ elif len(slope_shape) == 1 and input_rank >= 3:
138
+ slope_dim = slope_shape[0]
139
+ channel_axis = None
140
+ if isinstance(slope_dim, int):
141
+ if input_shape[1] == slope_dim:
142
+ channel_axis = 1
143
+ elif input_shape[-1] == slope_dim:
144
+ channel_axis = input_rank - 1
145
+ if channel_axis is not None:
146
+ shared_axes = [ax for ax in range(1, input_rank) if ax != channel_axis]
147
+
148
+ if shared_axes is None:
132
149
  if slope.shape is not None \
133
150
  and len(slope.shape) > 0 \
134
151
  and sum([1 if dim is not None and dim == 1 else 0 for dim in slope.shape]) == len(slope.shape):
135
152
  shared_axes = [val + 1 for val in range(len(input_tensor.shape) - 1)]
136
153
  else:
137
- shared_axes = [val + 1 for val in range(len(input_tensor.shape) - 2)]
138
- tf_layers_dict[graph_node_output.name]['tf_node'] = \
139
- PReLU(
140
- weights=slope,
141
- shared_axes=shared_axes,
142
- )(input_tensor)
154
+ input_nhwc = tf_layers_dict.get(graph_node_output.name, {}).get('nhwc', False)
155
+ if input_nhwc:
156
+ shared_axes = [val + 1 for val in range(len(input_tensor.shape) - 2)]
157
+ else:
158
+ shared_axes = [val + 2 for val in range(len(input_tensor.shape) - 2)]
159
+
160
+ use_native_prelu = not replace_prelu_to_pseudo_prelu
161
+ if not use_native_prelu:
162
+ pos = tf.nn.relu(input_tensor)
163
+ neg = (input_tensor - abs(input_tensor)) * (slope * 0.5)
164
+ tf_layers_dict[graph_node_output.name]['tf_node'] = pos + neg
165
+ else:
166
+ try:
167
+ tf_layers_dict[graph_node_output.name]['tf_node'] = \
168
+ PReLU(
169
+ weights=slope,
170
+ shared_axes=shared_axes,
171
+ )(input_tensor)
172
+ except Exception:
173
+ pos = tf.nn.relu(input_tensor)
174
+ neg = (input_tensor - abs(input_tensor)) * (slope * 0.5)
175
+ tf_layers_dict[graph_node_output.name]['tf_node'] = pos + neg
143
176
 
144
177
  # Post-process transpose
145
178
  before_trans_shape = tf_layers_dict[graph_node_output.name]['tf_node'].shape
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onnx2tf
3
- Version: 1.29.22
3
+ Version: 1.29.23
4
4
  Summary: Self-Created Tools to convert ONNX files (NCHW) to TensorFlow/TFLite/Keras format (NHWC). The purpose of this tool is to solve the massive Transpose extrapolation problem in onnx-tensorflow (onnx-tf).
5
5
  Keywords: onnx,tensorflow,tflite,keras,deep-learning,machine-learning
6
6
  Author: Katsuya Hyodo
@@ -365,7 +365,7 @@ Video speed is adjusted approximately 50 times slower than actual speed.
365
365
  docker run --rm -it \
366
366
  -v `pwd`:/workdir \
367
367
  -w /workdir \
368
- ghcr.io/pinto0309/onnx2tf:1.29.22
368
+ ghcr.io/pinto0309/onnx2tf:1.29.23
369
369
 
370
370
  or
371
371
 
@@ -373,7 +373,7 @@ Video speed is adjusted approximately 50 times slower than actual speed.
373
373
  docker run --rm -it \
374
374
  -v `pwd`:/workdir \
375
375
  -w /workdir \
376
- docker.io/pinto0309/onnx2tf:1.29.22
376
+ docker.io/pinto0309/onnx2tf:1.29.23
377
377
 
378
378
  or
379
379
 
@@ -493,13 +493,20 @@ onnx2tf -i resnet18-v1-7.onnx -v info
493
493
  # without input OP name.
494
494
  # Note that if there are multiple input OPs, the zero dimension of all input OPs is
495
495
  # forced to be rewritten.
496
- # The `-ois` option allows undefined dimensions in all dimensions, including
497
- # the zero dimensionality, to be overwritten to a static shape, but requires
496
+ # The `-sh/--shape-hints` option provides shape hints for input tensors with undefined
497
+ # dimensions, significantly improving the conversion success rate for models with dynamic
498
+ # input shapes. Specifying this option in combination with the `-b` option will further
499
+ # improve the success rate of model conversion. The `-sh` option does not change ONNX
500
+ # input OPs to static shapes.
501
+ # The `-ois/--overwrite_input_shape` option allows undefined dimensions in all dimensions,
502
+ # including the zero dimensionality, to be overwritten to a static shape, but requires
498
503
  # the input OP name to be specified.
499
504
  # e.g. -ois data1:1,3,224,224 data2:1,255 data3:1,224,6
500
505
  wget https://github.com/PINTO0309/onnx2tf/releases/download/0.0.2/resnet18-v1-7.onnx
501
506
  onnx2tf -i resnet18-v1-7.onnx -b 1
502
507
  or
508
+ onnx2tf -i resnet18-v1-7.onnx -sh data:1,3,224,224 -b 1
509
+ or
503
510
  onnx2tf -i resnet18-v1-7.onnx -ois data:1,3,224,224
504
511
 
505
512
  # Suppress automatic transposition of input OPs from NCW, NCHW, NCDHW to NWC, NHWC, NDHWC.
@@ -1,4 +1,4 @@
1
- onnx2tf/__init__.py,sha256=EUJwryuQmTqI1Huqr9hrm1fJwxQqmGxUjAFgGvuB950,67
1
+ onnx2tf/__init__.py,sha256=UHUGx_MsU6r_wJE0gjKBbArcku-dgsuNhDOnc8lkSn0,67
2
2
  onnx2tf/__main__.py,sha256=2RSCQ7d4lc6CwD-rlGn9UicPFg-P5du7ZD_yh-kuBEU,57
3
3
  onnx2tf/onnx2tf.py,sha256=BC-BFMf8QUG7PtOvpwglhe1sc4FhTO8AMrdlxKUN5jc,208204
4
4
  onnx2tf/ops/Abs.py,sha256=V7btmCG_ZvK_qJovUsguq0ZMJ349mhNQ4FHSgzP_Yuo,4029
@@ -118,7 +118,7 @@ onnx2tf/ops/OneHot.py,sha256=OThLm1MF1X75zx7gep_qdnRHsTRZX_tqZxjt6pAVi7E,6489
118
118
  onnx2tf/ops/OptionalGetElement.py,sha256=Qg8Lix1_rdGtVWC-UNC91ekx3ztB-5_UtWkg67M2Z5E,3031
119
119
  onnx2tf/ops/OptionalHasElement.py,sha256=fyZMPBWvLVohsm8J5FLMlYGBDr6HVq5lh9jL-yKp-tk,3031
120
120
  onnx2tf/ops/Or.py,sha256=7gyUSgbEVVQBp2t3G93pZlHNn0ejJfZ3rbSDOnFgUi0,4586
121
- onnx2tf/ops/PRelu.py,sha256=pHbsffhb2rLZPPb9NdKUT4f5-lC0TXmbZVafookXo90,6314
121
+ onnx2tf/ops/PRelu.py,sha256=DxLBUgxQdO5IL1--xA5lbGq7dI-kr8UKn2Mf-4j8L5Q,7769
122
122
  onnx2tf/ops/Pad.py,sha256=xZOkZK-53sXU-d0nADAjR1wOpKqfzHeJjTmzwon6G4A,11883
123
123
  onnx2tf/ops/Pow.py,sha256=DZjrWQSyLw_BPXrKyoTqT9KJIxPfNxnYVcoTDBagDgM,7056
124
124
  onnx2tf/ops/QLinearAdd.py,sha256=OssQI0pd8KXdnCC8urCPKP8bpcvSX0D76bS7q4-xMSY,5027
@@ -211,7 +211,7 @@ onnx2tf/utils/enums.py,sha256=7c5TqetqB07VjyHoxJHfLgtqBqk9ZRyUF33fPOJR1IM,1649
211
211
  onnx2tf/utils/iterative_json_optimizer.py,sha256=qqeIxWGxrhcCYk8-ebWnblnOkzDCwi-nseipHzHR_bk,10436
212
212
  onnx2tf/utils/json_auto_generator.py,sha256=OC-SfKtUg7zUxaXTAg6kT0ShzIc3ByjDa3FNp173DtA,60302
213
213
  onnx2tf/utils/logging.py,sha256=yUCmPuJ_XiUItM3sZMcaMO24JErkQy7zZwVTYWAuiKg,1982
214
- onnx2tf-1.29.22.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
215
- onnx2tf-1.29.22.dist-info/entry_points.txt,sha256=GuhvLu7ZlYECumbmoiFlKX0mFPtFi_Ti9L-E5yuQqKs,42
216
- onnx2tf-1.29.22.dist-info/METADATA,sha256=eWX7J2epMkaxU8YW1paH77k23Lw7K4i_7WsJC9f6-is,156067
217
- onnx2tf-1.29.22.dist-info/RECORD,,
214
+ onnx2tf-1.29.23.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
215
+ onnx2tf-1.29.23.dist-info/entry_points.txt,sha256=GuhvLu7ZlYECumbmoiFlKX0mFPtFi_Ti9L-E5yuQqKs,42
216
+ onnx2tf-1.29.23.dist-info/METADATA,sha256=ZMCERN7Q5orWmi94swf-4tt_Y3AkAI2em3tF_sQGR7g,156531
217
+ onnx2tf-1.29.23.dist-info/RECORD,,