tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #4990: [TF][Relay] BatchNorm support with run-time mean and variance calculation
Date Fri, 06 Mar 2020 06:41:13 GMT
FrozenGene commented on a change in pull request #4990: [TF][Relay] BatchNorm support with
run-time mean and variance calculation
URL: https://github.com/apache/incubator-tvm/pull/4990#discussion_r388734493
 
 

 ##########
 File path: tests/python/frontend/tensorflow/test_bn_trainingmod.py
 ##########
 @@ -0,0 +1,61 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+BatchNorm without given mean and variance given testcases
+====================
+This article is a test script to test fused_batch_norm operators in TensorFlow frontend when
mean and variance are not given.
+"""
+import tvm
+import numpy as np
+import tensorflow as tf
+from tvm import relay
+from tensorflow.python.framework import graph_util
+
+def test_fusedbatchnorm():
+    g=tf.Graph()
+    with g.as_default(): 
+        input_tensor = tf.placeholder(tf.float32,shape=(1, 12, 12, 32), name='input')
+        alpha = tf.constant(np.random.rand(32,), dtype=tf.float32, name='alpha')
+        beta = tf.constant(np.random.rand(32,), dtype=tf.float32, name='beta')
+        bn = tf.nn.fused_batch_norm(x=input_tensor, offset=beta, scale=alpha, name='bn')
+        out = tf.identity(bn[0], name='sum')
+    data = np.random.rand(1, 12, 12, 32)
+    with tf.Session(graph=out.graph) as sess:
+        sess.run([tf.global_variables_initializer()])
+        tf_out = sess.run(out, feed_dict={input_tensor:data})
+        constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph_def,
['sum'])
+    
+
+    layout = None
+    target = 'llvm'
+    ctx=tvm.cpu(0)
+    mod, params = relay.frontend.from_tensorflow(constant_graph, layout=layout, outputs=['sum'])
+    with relay.build_config(opt_level=3):
+        graph, lib, params = relay.build(mod,
+                                     target=target,
+                                     target_host = target,
+                                     params=params)
 
 Review comment:
   Align. Make sure `target=target` keep the same align `relay.build(mod,`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message