You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/03/09 23:09:49 UTC

[GitHub] [tvm] mehrdadh commented on a change in pull request #7557: Clean up uTVM demo runtime, add ONNX model test and tutorial

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



##########
File path: tutorials/micro/micro_onnx.py
##########
@@ -0,0 +1,209 @@
+#!/usr/bin/env python3
+
+# 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.
+
+"""
+microTVM with ONNX models
+=========================
+**Author**: `Matt Welsh <https://www.mdw.la/>`
+
+This tutorial is an introduction to compiling and
+running an ONNX model on a device using microTVM.
+"""
+
+# Setup
+# -----
+#
+# Build TVM wth ``USE_MICRO``
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# Download the TVM sources, and build TVM from source following the
+# instructions `on this page
+# <https://tvm.apache.org/docs/install/from_source.html#install-from-source>`.
+# When bulding TVM, ensure that the following lines are present in
+# your ``config.cmake`` file:
+# .. code-block:: bash
+#
+#    # Whether enable MicroTVM runtime
+#    set(USE_MICRO ON)
+#
+# Install Python dependencies
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# microTVM and this tutorial require a number of Python dependencies --
+# in addition to TVM itself -- to be installed in your Python environment.
+# For convenience, we have provided a `Poetry <https://python-poetry.org/>`
+# ``pyproject.toml`` configuration file in the directory ``apps/microtvm``.
+# You can use this as follows:
+#
+# .. code-block:: bash
+#
+#    $ cd $TVM_HOME/apps/microtvm
+#    $ poetry lock && poetry install
+#    $ poetry shell
+#
+# You should now be in a Python virtual environment with all of the appropriate
+# dependencies installed.
+#
+# Install Zephyr
+# ^^^^^^^^^^^^^^
+#
+# microTVM currently uses the `Zephyr <https://zephyrproject.org>` RTOS as
+# the basis for the device-side runtime. To get started, install Zephyr
+# and an appropriate device-specific toolchain using the
+# `Zephyr installation instructions <https://docs.zephyrproject.org/latest/getting_started/index.html>`_.
+#
+# Be sure you are able to build and flash a sample Zephyr program
+# (e.g., the "Blinky" demo) to your device before you proceed with this tutorial.
+
+import datetime
+import io
+import os
+import sys
+
+import onnx
+import tvm
+import tvm.micro
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import graph_runtime as runtime
+from tvm.micro.contrib import zephyr
+from PIL import Image
+import numpy as np
+
+######################################################################
+# For this tutorial, we use a pretrained ONNX model implementing
+# the MNIST handwritten digit recognition on 28x28 px input images.
+
+MODEL_FILE = "../../tests/micro/zephyr/testdata/mnist-8.onnx"

Review comment:
       I think this file is missing.




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