From commits-return-8081-archive-asf-public=cust-asf.ponee.io@tvm.apache.org Sat Mar 7 05:37:57 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id B295118025F for ; Sat, 7 Mar 2020 06:37:56 +0100 (CET) Received: (qmail 77489 invoked by uid 500); 7 Mar 2020 05:37:56 -0000 Mailing-List: contact commits-help@tvm.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tvm.apache.org Delivered-To: mailing list commits@tvm.apache.org Received: (qmail 77480 invoked by uid 99); 7 Mar 2020 05:37:56 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Mar 2020 05:37:56 +0000 From: GitBox To: commits@tvm.apache.org Subject: [GitHub] [incubator-tvm] lfengad commented on a change in pull request #4990: [TF][Relay] BatchNorm support with run-time mean and variance calculation Message-ID: <158355947588.30052.17128136522411623045.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Sat, 07 Mar 2020 05:37:55 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit lfengad 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_r389230534 ########## File path: tests/python/frontend/tensorflow/test_bn_dynamic.py ########## @@ -0,0 +1,71 @@ +# 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 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 verify_fused_batch_norm(shape): + g = tf.Graph() + with g.as_default(): + input_tensor = tf.placeholder(tf.float32, shape=shape, name='input') + alpha = tf.constant(np.random.rand(shape[-1],), dtype=tf.float32, name='alpha') + beta = tf.constant(np.random.rand(shape[-1],), 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='output') + data = np.random.rand(*shape) + 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, ['output']) + + for device in ["llvm"]: + ctx = tvm.context(device, 0) + if not ctx.exist: + print("Skip because %s is not enabled" % device) + continue + mod, params = relay.frontend.from_tensorflow(constant_graph, + outputs=['output']) + with relay.build_config(opt_level=3): + graph, lib, params = relay.build(mod, + target=device, + params=params) + from tvm.contrib import graph_runtime + m = graph_runtime.create(graph, lib, ctx) + m.set_input(**params) + m.set_input('input', data) + m.run() + tvm_out = m.get_output(0) + tvm.testing.assert_allclose(tvm_out.asnumpy(), tf_out.astype(tvm_out.dtype), rtol=1e-1) Review comment: Okay, I can try it. Thank you for the suggestions! ---------------------------------------------------------------- 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