onnx2tf 1.27.7__py3-none-any.whl → 1.27.8__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.27.7'
3
+ __version__ = '1.27.8'
@@ -167,11 +167,46 @@ def make_node(
167
167
  input_tensor=input_tensor
168
168
  )
169
169
 
170
- func = math.ceil if ceil_mode else math.floor
171
- output_spatial_shape = [
172
- func((i + pb + pe - d * (k - 1) - 1) / s + 1)
173
- for i, pb, pe, k, d, s in zip(input_tensor_shape[1:-1], pads[:len(pads) // 2], pads[len(pads) // 2:], kernel_shape, dilations, strides)
174
- ]
170
+ if not is_known_shape:
171
+ def compute_output_spatial_shape_from_tensor(input_tensor, pads, kernel_shape, dilations, strides, ceil_mode=False):
172
+ input_shape = tf.shape(input_tensor) # Get dynamic shape
173
+ input_spatial = input_shape[1:-1] # Extract spatial dimensions only (NHWC format)
174
+
175
+ pad_begin = pads[:len(pads) // 2]
176
+ pad_end = pads[len(pads) // 2:]
177
+
178
+ round_func = tf.math.ceil if ceil_mode else tf.math.floor
179
+
180
+ output_spatial = []
181
+ for i, pb, pe, k, d, s in zip(tf.unstack(input_spatial), pad_begin, pad_end, kernel_shape, dilations, strides):
182
+ i = tf.cast(i, tf.float32)
183
+ pb = tf.constant(pb, dtype=tf.float32)
184
+ pe = tf.constant(pe, dtype=tf.float32)
185
+ k = tf.constant(k, dtype=tf.float32)
186
+ d = tf.constant(d, dtype=tf.float32)
187
+ s = tf.constant(s, dtype=tf.float32)
188
+
189
+ numerator = i + pb + pe - d * (k - 1) - 1
190
+ raw_output = numerator / s + 1
191
+ output_dim = tf.cast(round_func(raw_output), tf.int32)
192
+ output_spatial.append(output_dim)
193
+
194
+ return output_spatial
195
+
196
+ output_spatial_shape = compute_output_spatial_shape_from_tensor(
197
+ input_tensor=input_tensor,
198
+ pads=pads,
199
+ kernel_shape=kernel_shape,
200
+ dilations=dilations,
201
+ strides=strides,
202
+ ceil_mode=ceil_mode
203
+ )
204
+ else:
205
+ func = math.ceil if ceil_mode else math.floor
206
+ output_spatial_shape = [
207
+ func((i + pb + pe - d * (k - 1) - 1) / s + 1)
208
+ for i, pb, pe, k, d, s in zip(input_tensor_shape[1:-1], pads[:len(pads) // 2], pads[len(pads) // 2:], kernel_shape, dilations, strides)
209
+ ]
175
210
 
176
211
  # onnx padding value is ignored if auto_pad is not 'NOTSET'
177
212
  if auto_pad == 'NOTSET':
@@ -218,28 +253,52 @@ def make_node(
218
253
  # count nonzero elements in kernel each strides for the case count_include_pad is False
219
254
  non_zero_counts = []
220
255
 
221
- for input_spatial_shape, output_size, kernel, dilation, stride, pads_begin, pads_end \
222
- in zip(input_tensor_shape[1:-1], output_spatial_shape, kernel_shape,
223
- dilations, strides, pads[:len(pads) // 2], pads[len(pads) // 2:]):
224
- sample_target = np.concatenate([
225
- np.zeros(pads_begin),
226
- np.ones(input_spatial_shape),
227
- np.zeros(pads_end)]
256
+ if not is_known_shape:
257
+ def compute_non_zero_counts_loop(input_tensor, output_spatial_shape, kernel_shape, dilations, strides, pads):
258
+
259
+ counts_list = []
260
+
261
+ for dim in range(len(kernel_shape)):
262
+ k = kernel_shape[dim]
263
+ counts = [k] * (output_spatial_shape[dim].numpy() if tf.is_tensor(output_spatial_shape[dim]) and hasattr(output_spatial_shape[dim], 'numpy') else output_spatial_shape[dim])
264
+ counts_list.append(counts)
265
+
266
+ return counts_list
267
+
268
+ non_zero_counts = compute_non_zero_counts_loop(
269
+ input_tensor=input_tensor,
270
+ output_spatial_shape=output_spatial_shape,
271
+ kernel_shape=kernel_shape,
272
+ dilations=dilations,
273
+ strides=strides,
274
+ pads=pads
228
275
  )
229
- sample_kernel = np.zeros((kernel - 1) * dilation + 1)
230
- sample_kernel[::dilation] = 1
276
+ else:
277
+ for input_spatial_shape, output_size, kernel, dilation, stride, pads_begin, pads_end \
278
+ in zip(input_tensor_shape[1:-1], output_spatial_shape, kernel_shape,
279
+ dilations, strides, pads[:len(pads) // 2], pads[len(pads) // 2:]):
280
+ sample_target = np.concatenate([
281
+ np.zeros(pads_begin),
282
+ np.ones(input_spatial_shape),
283
+ np.zeros(pads_end)]
284
+ )
285
+ sample_kernel = np.zeros((kernel - 1) * dilation + 1)
286
+ sample_kernel[::dilation] = 1
231
287
 
232
- counts = []
233
- for i in range(output_size):
234
- start = i * stride
235
- stride_target = sample_target[start:start+len(sample_kernel)]
236
- # pad target to match size
237
- stride_target = np.concatenate([stride_target, np.zeros(len(sample_kernel) - len(stride_target))])
238
- counts.extend(np.convolve(stride_target, sample_kernel, mode='valid'))
288
+ counts = []
289
+ for i in range(output_size):
290
+ start = i * stride
291
+ stride_target = sample_target[start:start+len(sample_kernel)]
292
+ # pad target to match size
293
+ stride_target = np.concatenate([stride_target, np.zeros(len(sample_kernel) - len(stride_target))])
294
+ counts.extend(np.convolve(stride_target, sample_kernel, mode='valid'))
239
295
 
240
- non_zero_counts.append(counts)
296
+ non_zero_counts.append(counts)
241
297
 
242
- need_multiplier = len(set([i for sublist in non_zero_counts for i in sublist])) != 1
298
+ if not is_known_shape:
299
+ need_multiplier = False # Default to False for dynamic tensors to avoid errors
300
+ else:
301
+ need_multiplier = len(set([i for sublist in non_zero_counts for i in sublist])) != 1
243
302
 
244
303
  # default tensorflow option for count_include_pad is True and cannot control
245
304
  # average value should be compensated in cases below
@@ -295,7 +354,9 @@ def make_node(
295
354
  multiplier[-1] = k / (k - extra_pad)
296
355
  average_multiplier.append(multiplier)
297
356
  else:
298
- for i, k, non_zero_count, extra_pad in enumerate(zip(kernel_shape, non_zero_counts, extra_pads)):
357
+ for i in range(len(kernel_shape)):
358
+ k = kernel_shape[i]
359
+ extra_pad = extra_pads[i]
299
360
  average_multiplier[i][-1] = k / (k - extra_pad)
300
361
 
301
362
  # Preserving Graph Structure (Dict)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onnx2tf
3
- Version: 1.27.7
3
+ Version: 1.27.8
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
  Home-page: https://github.com/PINTO0309/onnx2tf
6
6
  Author: Katsuya Hyodo
@@ -334,7 +334,7 @@ Video speed is adjusted approximately 50 times slower than actual speed.
334
334
  docker run --rm -it \
335
335
  -v `pwd`:/workdir \
336
336
  -w /workdir \
337
- ghcr.io/pinto0309/onnx2tf:1.27.7
337
+ ghcr.io/pinto0309/onnx2tf:1.27.8
338
338
 
339
339
  or
340
340
 
@@ -342,7 +342,7 @@ Video speed is adjusted approximately 50 times slower than actual speed.
342
342
  docker run --rm -it \
343
343
  -v `pwd`:/workdir \
344
344
  -w /workdir \
345
- docker.io/pinto0309/onnx2tf:1.27.7
345
+ docker.io/pinto0309/onnx2tf:1.27.8
346
346
 
347
347
  or
348
348
 
@@ -1,4 +1,4 @@
1
- onnx2tf/__init__.py,sha256=T9ZWYLI8Cr8oH2EHbgRHp0VPs8l0KxcEqAyWcOBf9fQ,66
1
+ onnx2tf/__init__.py,sha256=FA0T9QrV9uxJnT2OPSYDXM4XnIfbdPVzPKxKz-BfM6s,66
2
2
  onnx2tf/__main__.py,sha256=2RSCQ7d4lc6CwD-rlGn9UicPFg-P5du7ZD_yh-kuBEU,57
3
3
  onnx2tf/onnx2tf.py,sha256=KPFVEhTDBhX7Y-Bh7X40ZEclGf2_Vfp9-M9AMPqOywI,123892
4
4
  onnx2tf/ops/Abs.py,sha256=V7btmCG_ZvK_qJovUsguq0ZMJ349mhNQ4FHSgzP_Yuo,4029
@@ -12,7 +12,7 @@ onnx2tf/ops/Asin.py,sha256=2djUjTaOzXM6t4Qb-EEMZY-pm1rJl24cgcrep2i_6aQ,4003
12
12
  onnx2tf/ops/Asinh.py,sha256=74ZzTEkpxZY4CGfJT2JJU-SHXYL5KZeUkWY2v7hsMMw,3588
13
13
  onnx2tf/ops/Atan.py,sha256=D24XDMxEwXFtJheQAr3V3IWOUOc6Q5M0-b_83bmGGMM,3981
14
14
  onnx2tf/ops/Atanh.py,sha256=VsUYopBWWPoo4gta1_aqvUL6NrVXuVkGid4SqDqYJ9Q,3588
15
- onnx2tf/ops/AveragePool.py,sha256=p9R4k87FO1yKZMQ699FIftXGUNKxb5yu0vYfzPlpsMA,14701
15
+ onnx2tf/ops/AveragePool.py,sha256=X2uMuo1CnPBpeqXbCkG-hMBmmUFGry-Xu4EXLg2aoIw,17297
16
16
  onnx2tf/ops/BatchNormalization.py,sha256=_hlf2-5-j3MCJHEoE2oMNQ8YhCm7ad9h2fwPpTo3i7g,26624
17
17
  onnx2tf/ops/Bernoulli.py,sha256=PM0xS0n1q4bnT_9PnbcKW8_Qj8dJYYBQR8kb2X-wIp4,3670
18
18
  onnx2tf/ops/BitShift.py,sha256=a28_E9hwA8yfjvtsrSKCZCeeMPB5RBQbjB3cmaNGN6k,3861
@@ -188,10 +188,10 @@ onnx2tf/utils/__init__.py,sha256=E9FM9He68VIASDnYp-OrxvHFVn55GzWqw2OEkCqn1zg,27
188
188
  onnx2tf/utils/common_functions.py,sha256=TXvZ7qg9stD1qKvbtkoE70jRxojdtdQhhHIoYaM0I1E,241826
189
189
  onnx2tf/utils/enums.py,sha256=7c5TqetqB07VjyHoxJHfLgtqBqk9ZRyUF33fPOJR1IM,1649
190
190
  onnx2tf/utils/logging.py,sha256=yUCmPuJ_XiUItM3sZMcaMO24JErkQy7zZwVTYWAuiKg,1982
191
- onnx2tf-1.27.7.dist-info/licenses/LICENSE,sha256=5v_Kxihy8i6mzHVl349ikSREaIdsl9YeUnX1KBDLD2w,1070
192
- onnx2tf-1.27.7.dist-info/licenses/LICENSE_onnx-tensorflow,sha256=gK4GtS9S5YcyINu6uuNNWdo-kBClyEM4MFLFGiNTeRM,11231
193
- onnx2tf-1.27.7.dist-info/METADATA,sha256=83NqwMo1_sVzH1VVUyzVhh_0QT5rSg2m4LfoP3VDrZo,147712
194
- onnx2tf-1.27.7.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
195
- onnx2tf-1.27.7.dist-info/entry_points.txt,sha256=gDPK8ToCFPKMvm8jr9xrGOkXtORJJVh4736fBEKO5k0,41
196
- onnx2tf-1.27.7.dist-info/top_level.txt,sha256=WgfPiEy3f6vZ_FOpAIEA2CF3TCx1eYrhGw93Ih6b9Fw,8
197
- onnx2tf-1.27.7.dist-info/RECORD,,
191
+ onnx2tf-1.27.8.dist-info/licenses/LICENSE,sha256=5v_Kxihy8i6mzHVl349ikSREaIdsl9YeUnX1KBDLD2w,1070
192
+ onnx2tf-1.27.8.dist-info/licenses/LICENSE_onnx-tensorflow,sha256=gK4GtS9S5YcyINu6uuNNWdo-kBClyEM4MFLFGiNTeRM,11231
193
+ onnx2tf-1.27.8.dist-info/METADATA,sha256=LemcJx7-r_QtmIE02r6C6XUgQKnDKGzOsyWyCF-1s5s,147712
194
+ onnx2tf-1.27.8.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
195
+ onnx2tf-1.27.8.dist-info/entry_points.txt,sha256=gDPK8ToCFPKMvm8jr9xrGOkXtORJJVh4736fBEKO5k0,41
196
+ onnx2tf-1.27.8.dist-info/top_level.txt,sha256=WgfPiEy3f6vZ_FOpAIEA2CF3TCx1eYrhGw93Ih6b9Fw,8
197
+ onnx2tf-1.27.8.dist-info/RECORD,,