Skip to content

Commit

Permalink
Import pyserial only when needed
Browse files Browse the repository at this point in the history
Changes from code review

Use official sphinx-gallery repo

Correctly specify version

Import pyserial only when necessary
  • Loading branch information
guberti committed May 20, 2022
1 parent e7f3879 commit ff377e9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import re

from packaging import version
import serial.tools.list_ports

from tvm.micro.project_api import server

Expand Down Expand Up @@ -485,6 +484,9 @@ def flash(self, options):
subprocess.run(upload_cmd, check=True)

def open_transport(self, options):
import serial
import serial.tools.list_ports

# Zephyr example doesn't throw an error in this case
if self._serial is not None:
return
Expand Down
2 changes: 1 addition & 1 deletion apps/microtvm/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ importer-tflite = ["tflite", "tensorflow", "tensorflow-estimator"]
autodocsumm = "^0.1"
black = "^19.10b0"
sphinx = "^3.0"
sphinx-gallery = "^0.8"
sphinx-gallery = { git = "https://github.com/sphinx-gallery/sphinx-gallery.git", branch = "master" }
sphinx-rtd-theme = "^0.4"
matplotlib = "^3.2"
Image = "^1.5"
Expand Down
2 changes: 1 addition & 1 deletion docker/install/ubuntu_install_sphinx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ pip3 install \
matplotlib \
sphinx==4.2.0 \
sphinx_autodoc_annotation \
sphinx-gallery==0.4.0 \
"git+https://github.com/sphinx-gallery/sphinx-gallery.git" \
sphinx_rtd_theme
24 changes: 13 additions & 11 deletions gallery/how_to/work_with_microtvm/micro_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# .. image:: https://raw.githubusercontent.com/guberti/web-data/micro-train-tutorial-data/images/utilities/colab_button.png
# :align: center
# :target: https://colab.research.google.com/github/guberti/tvm-site/blob/asf-site/docs/_downloads/a7c7ea4b5017ae70db1f51dd8e6dcd82/micro_train.ipynb
# :width: 600px
# :width: 300px
#
# Motivation
# ----------
Expand Down Expand Up @@ -258,16 +258,17 @@
#
# Our applications generally don't need perfect accuracy - 90% is good enough. We can thus use the
# older and smaller MobileNet V1 architecture. But this *still* won't be small enough - by default,
# MobileNet V1 with 224x224 inputs and depth 1.0 takes ~50 MB to just **store**. To reduce the size
# MobileNet V1 with 224x224 inputs and alpha 1.0 takes ~50 MB to just **store**. To reduce the size
# of the model, there are three knobs we can turn. First, we can reduce the size of the input images
# from 224x224 to 96x96 or 64x64, and Keras makes it easy to do this. We can also reduce the **depth**
# of the model, from 1.0 to 0.25. And if we were really strapped for space, we could reduce the
# from 224x224 to 96x96 or 64x64, and Keras makes it easy to do this. We can also reduce the **alpha**
# of the model, from 1.0 to 0.25, which downscales the width of the network (and the number of
# filters) by a factor of four. And if we were really strapped for space, we could reduce the
# number of **channels** by making our model take grayscale images instead of RGB ones.
#
# In this tutorial, we will use an RGB 64x64 input image and 0.25 depth scale. This is not quite
# In this tutorial, we will use an RGB 64x64 input image and alpha 0.25. This is not quite
# ideal, but it allows the finished model to fit in 192 KB of RAM, while still letting us perform
# transfer learning using the official Tensorflow source models (if we used depth scale <0.25 or
# a grayscale input, we wouldn't be able to do this).
# transfer learning using the official Tensorflow source models (if we used alpha <0.25 or a
# grayscale input, we wouldn't be able to do this).
#
# What is Transfer Learning?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -369,14 +370,12 @@
# the conversion. By default, TFLite keeps the inputs and outputs of our model as floats, so we must
# explicitly tell it to avoid this behavior.

converter = tf.lite.TFLiteConverter.from_keras_model(model)


def representative_dataset():
for image_batch, label_batch in full_dataset.take(10):
yield [image_batch]


converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
Expand Down Expand Up @@ -431,7 +430,7 @@ def representative_dataset():
#
# Generating our project
# ^^^^^^^^^^^^^^^^^^^^^^
# Next, we'll compile the model to TVM's MLF (machine learning format) intermediate representation,
# Next, we'll compile the model to TVM's MLF (model library format) intermediate representation,
# which consists of C/C++ code and is designed for autotuning. To improve performance, we'll tell
# TVM that we're compiling for the ``nrf52840`` microprocessor (the one the Nano 33 BLE uses). We'll
# also tell it to use the C runtime (abbreviated ``crt``) and to use ahead-of-time memory allocation
Expand Down Expand Up @@ -563,6 +562,9 @@ def representative_dataset():
# not throw any compiler errors:

shutil.rmtree(f"{FOLDER}/models/project/build", ignore_errors=True)
# sphinx_gallery_start_ignore
arduino_project = MagicMock()
# sphinx_gallery_end_ignore
arduino_project.build()
print("Compilation succeeded!")

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def docs(
"tlcpack-sphinx-addon==0.2.1",
"synr==0.5.0",
"image==1.5.33",
"git+https://github.com/guberti/sphinx-gallery.git@ipynb-include-bash",
"git+https://github.com/sphinx-gallery/sphinx-gallery.git",
"sphinx-rtd-theme==1.0.0",
"matplotlib==3.3.4",
"commonmark==0.9.1",
Expand Down

0 comments on commit ff377e9

Please sign in to comment.