onnx2tf 1.29.5__py3-none-any.whl → 1.29.7__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.
@@ -0,0 +1,115 @@
1
+ import random
2
+ random.seed(0)
3
+ import numpy as np
4
+ np.random.seed(0)
5
+ import tensorflow as tf
6
+ from onnx import TensorProto
7
+ import onnx_graphsurgeon as gs
8
+ from onnx2tf.utils.common_functions import (
9
+ get_constant_or_variable,
10
+ print_node_info,
11
+ inverted_operation_enable_disable,
12
+ make_tf_node_info,
13
+ get_replacement_parameter,
14
+ pre_process_transpose,
15
+ post_process_transpose,
16
+ )
17
+ from onnx2tf.utils.enums import ONNX_DTYPES_TO_TF_DTYPES
18
+
19
+
20
+ @print_node_info
21
+ @inverted_operation_enable_disable
22
+ @get_replacement_parameter
23
+ def make_node(
24
+ *,
25
+ graph_node: gs.Node,
26
+ tf_layers_dict: dict,
27
+ **kwargs: dict,
28
+ ):
29
+ """BlackmanWindow
30
+
31
+ Parameters
32
+ ----------
33
+ graph_node: gs.Node
34
+ graph_surgeon Node
35
+
36
+ tf_layers_dict: dict
37
+ optype, shape, dtype, tensorflow graph
38
+ """
39
+ graph_node_input_1 = get_constant_or_variable(
40
+ graph_node.inputs[0],
41
+ before_op_output_shape_trans=False,
42
+ )
43
+ size = tf_layers_dict[graph_node_input_1.name]['tf_node'] \
44
+ if isinstance(graph_node_input_1, gs.Variable) else graph_node_input_1
45
+
46
+ graph_node_output: gs.Variable = graph_node.outputs[0]
47
+
48
+ shape = graph_node_output.shape
49
+ dtype = graph_node_output.dtype
50
+
51
+ output_datatype = int(graph_node.attrs.get('output_datatype', TensorProto.FLOAT))
52
+ output_datatype = ONNX_DTYPES_TO_TF_DTYPES[output_datatype]
53
+ periodic = bool(graph_node.attrs.get('periodic', 1))
54
+
55
+ # Preserving Graph Structure (Dict)
56
+ tf_layers_dict[graph_node_output.name] = {
57
+ 'optype': graph_node.op,
58
+ 'shape': shape,
59
+ 'dtype': dtype,
60
+ }
61
+
62
+ # Pre-process transpose
63
+ size = pre_process_transpose(
64
+ value_before_transpose=size,
65
+ param_target='inputs',
66
+ param_name=graph_node.inputs[0].name,
67
+ **kwargs,
68
+ )
69
+
70
+ # Generation of TF OP
71
+ size_fp = tf.cast(size, tf.float32)
72
+ periodic_size_fp = size_fp
73
+ symmetric_size_fp = size_fp - tf.constant(1.0, dtype=tf.float32)
74
+ is_periodic_fp = tf.cast(periodic, tf.float32)
75
+ size_fp = periodic_size_fp * is_periodic_fp + symmetric_size_fp * (1.0 - is_periodic_fp)
76
+
77
+ two_pi = tf.constant(6.28319, dtype=tf.float32)
78
+ angular_increment = tf.math.divide_no_nan(two_pi, size_fp)
79
+ range_vals = tf.range(tf.cast(periodic_size_fp, tf.int32), dtype=tf.float32)
80
+ range_angular = range_vals * angular_increment
81
+
82
+ a0 = tf.constant(0.42, dtype=tf.float32)
83
+ a1 = tf.constant(0.5, dtype=tf.float32)
84
+ a2 = tf.constant(0.08, dtype=tf.float32)
85
+
86
+ temp0 = a0 - a1 * tf.cos(range_angular)
87
+ temp1 = temp0 + a2 * tf.cos(range_angular * 2.0)
88
+ tf_layers_dict[graph_node_output.name]['tf_node'] = tf.cast(
89
+ temp1,
90
+ dtype=output_datatype,
91
+ )
92
+
93
+ # Post-process transpose
94
+ tf_layers_dict[graph_node_output.name]['tf_node'] = post_process_transpose(
95
+ value_before_transpose=tf_layers_dict[graph_node_output.name]['tf_node'],
96
+ param_target='outputs',
97
+ param_name=graph_node.outputs[0].name,
98
+ **kwargs,
99
+ )
100
+
101
+ # Generation of Debug Info
102
+ tf_layers_dict[graph_node_output.name]['tf_node_info'] = \
103
+ make_tf_node_info(
104
+ node_info={
105
+ 'tf_op_type': 'BlackmanWindow',
106
+ 'tf_inputs': {
107
+ 'size': size,
108
+ 'periodic': periodic,
109
+ 'dtype': output_datatype,
110
+ },
111
+ 'tf_outputs': {
112
+ 'output': tf_layers_dict[graph_node_output.name]['tf_node'],
113
+ },
114
+ }
115
+ )