Skip to content

Commit

Permalink
Remove Depracated TF2ONNX UT Case (#1843)
Browse files Browse the repository at this point in the history
Signed-off-by: zehao-intel <[email protected]>
  • Loading branch information
zehao-intel authored Jun 5, 2024
1 parent daa1431 commit 82fc480
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions test/itex/test_tensorflow_qdq_convert_to_onnx_qdq.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,65 +57,6 @@ def tearDownClass(self):
if version1_gte_version2(tf.version.VERSION, "2.8.0"):
shutil.rmtree("workspace")

@disable_random()
@unittest.skipIf(version1_lt_version2(tf.version.VERSION, "2.8.0"), "Only supports tf greater 2.7.0")
def test_convert_tf_qdq_to_onnx_qdq(self):
x = tf.compat.v1.placeholder(tf.float32, [1, 56, 56, 16], name="input")
top_relu = tf.nn.relu(x)
paddings = tf.constant([[0, 0], [1, 1], [1, 1], [0, 0]])
x_pad = tf.pad(top_relu, paddings, "CONSTANT")
conv_weights = tf.compat.v1.get_variable(
"weight", [3, 3, 16, 16], initializer=tf.compat.v1.random_normal_initializer()
)
conv = tf.nn.conv2d(x_pad, conv_weights, strides=[1, 2, 2, 1], padding="VALID")
normed = tf.compat.v1.layers.batch_normalization(conv)

conv_weights2 = tf.compat.v1.get_variable(
"weight2", [3, 3, 16, 16], initializer=tf.compat.v1.random_normal_initializer()
)
conv2 = tf.nn.conv2d(top_relu, conv_weights2, strides=[1, 2, 2, 1], padding="SAME")
add = tf.raw_ops.Add(x=normed, y=conv2, name="addv2")
relu = tf.nn.relu(add)
relu6 = tf.nn.relu6(relu, name="op_to_store")

out_name = relu6.name.split(":")[0]
with tf.compat.v1.Session() as sess:
sess.run(tf.compat.v1.global_variables_initializer())
output_graph_def = graph_util.convert_variables_to_constants(
sess=sess, input_graph_def=sess.graph_def, output_node_names=[out_name]
)

quantizer = Quantization("fake_yaml.yaml")
dataset = quantizer.dataset("dummy", shape=(100, 56, 56, 16), label=True)
quantizer.eval_dataloader = common.DataLoader(dataset)
quantizer.calib_dataloader = common.DataLoader(dataset)

quantizer.model = output_graph_def
output_graph = quantizer.fit()

from neural_compressor.config import TF2ONNXConfig

config = TF2ONNXConfig()
output_graph.export("workspace/tf_qdq_to_onnx_qdq.onnx", config)

import onnx

onnx_model = onnx.load("workspace/tf_qdq_to_onnx_qdq.onnx")
onnx.checker.check_model(onnx_model)

import onnxruntime as ort

from neural_compressor.data import DATALOADERS, Datasets

ort_session = ort.InferenceSession("workspace/tf_qdq_to_onnx_qdq.onnx")
dataset = Datasets("tensorflow")["dummy"]((100, 56, 56, 16))
dataloader = DATALOADERS["tensorflow"](dataset)
it = iter(dataloader)
input = next(it)
input_dict = {"input:0": input[0]}
outputs = ort_session.run(None, input_dict)
self.assertNotEqual(outputs, None)

@disable_random()
@unittest.skipIf(version1_lt_version2(tf.version.VERSION, "2.8.0"), "Only supports tf greater 2.7.0")
def test_convert_tf_fp32_to_onnx_fp32(self):
Expand Down

0 comments on commit 82fc480

Please sign in to comment.