mehrdadh commented on a change in pull request #8715:
URL: https://github.com/apache/tvm/pull/8715#discussion_r687961144



##########
File path: tutorials/micro/micro_autotune.py
##########
@@ -0,0 +1,269 @@
+# 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.
+
+"""
+.. _tutorial-micro-autotune:
+
+Autotuning with micro TVM
+=========================
+**Author**: `Andrew Reusch <https://github.com/areusch>`_, `Mehrdad Hessar 
<https://github.com/mehrdadh>`
+
+This tutorial explains how to autotune a model using the C runtime.
+"""
+
+import argparse
+from tvm.contrib import utils
+
+
+PLATFORMS = {
+    "host": ("host", None),
+    "qemu_x86": ("host", "qemu_x86"),
+    "nrf5340dk": ("nrf5340dk", "nrf5340dk_nrf5340_cpuapp"),
+    "stm32f746xx_disco": ("stm32f746xx", "stm32f746g_disco"),
+    "stm32f746xx_nucleo": ("stm32f746xx", "nucleo_f746zg"),
+    "stm32l4r5zi_nucleo": ("stm32l4r5zi", "nucleo_l4r5zi"),
+}
+
+
+def main(args):
+    ####################
+    # Defining the model
+    ####################
+    #
+    # To begin with, define a model in Keras to be executed on-device. This 
shouldn't look any different
+    # from a usual Keras model definition. Let's define a relatively small 
model here for efficiency's
+    # sake.
+
+    import tensorflow as tf
+    from tensorflow import keras
+
+    model = keras.models.Sequential()
+    model.add(keras.layers.Conv2D(2, 3, input_shape=(16, 16, 3)))
+    model.build()
+
+    model.summary()
+
+    ####################
+    # Importing into TVM
+    ####################
+    # Now, use `from_keras 
<https://tvm.apache.org/docs/api/python/relay/frontend.html#tvm.relay.frontend.from_keras>`_
 to import the Keras model into TVM.
+
+    import tvm
+    from tvm import relay
+    import numpy as np
+
+    inputs = {
+        i.name.split(":", 2)[0]: [x if x is not None else 1 for x in 
i.shape.as_list()]
+        for i in model.inputs
+    }
+    inputs = {k: [v[0], v[3], v[1], v[2]] for k, v in inputs.items()}
+    tvm_model, params = relay.frontend.from_keras(model, inputs, layout="NCHW")
+    print(tvm_model)
+
+    #######################
+    # Defining the target #
+    #######################
+    # Now we define the TVM target that describes the execution environment. 
This looks very similar
+    # to target definitions from other microTVM tutorials.
+    #
+    # When running on physical hardware, choose a target and a board that
+    # describe the hardware. There are multiple hardware targets that could be 
selected from
+    # PLATFORM list in this tutorial. You can chose the platform by passing 
--platform argument when running
+    # this tutorial.
+    #
+    TARGET = tvm.target.target.micro(PLATFORMS[args.platform][0])
+    BOARD = PLATFORMS[args.platform][1]

Review comment:
       done.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to