Skip to content

Commit ff377e9

Browse files
committed
Import pyserial only when needed
Changes from code review Use official sphinx-gallery repo Correctly specify version Import pyserial only when necessary
1 parent e7f3879 commit ff377e9

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

apps/microtvm/arduino/template_project/microtvm_api_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import re
3535

3636
from packaging import version
37-
import serial.tools.list_ports
3837

3938
from tvm.micro.project_api import server
4039

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

487486
def open_transport(self, options):
487+
import serial
488+
import serial.tools.list_ports
489+
488490
# Zephyr example doesn't throw an error in this case
489491
if self._serial is not None:
490492
return

apps/microtvm/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ importer-tflite = ["tflite", "tensorflow", "tensorflow-estimator"]
129129
autodocsumm = "^0.1"
130130
black = "^19.10b0"
131131
sphinx = "^3.0"
132-
sphinx-gallery = "^0.8"
132+
sphinx-gallery = { git = "https://github.com/sphinx-gallery/sphinx-gallery.git", branch = "master" }
133133
sphinx-rtd-theme = "^0.4"
134134
matplotlib = "^3.2"
135135
Image = "^1.5"

docker/install/ubuntu_install_sphinx.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ pip3 install \
2929
matplotlib \
3030
sphinx==4.2.0 \
3131
sphinx_autodoc_annotation \
32-
sphinx-gallery==0.4.0 \
32+
"git+https://github.com/sphinx-gallery/sphinx-gallery.git" \
3333
sphinx_rtd_theme

gallery/how_to/work_with_microtvm/micro_train.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# .. image:: https://raw.githubusercontent.com/guberti/web-data/micro-train-tutorial-data/images/utilities/colab_button.png
3737
# :align: center
3838
# :target: https://colab.research.google.com/github/guberti/tvm-site/blob/asf-site/docs/_downloads/a7c7ea4b5017ae70db1f51dd8e6dcd82/micro_train.ipynb
39-
# :width: 600px
39+
# :width: 300px
4040
#
4141
# Motivation
4242
# ----------
@@ -258,16 +258,17 @@
258258
#
259259
# Our applications generally don't need perfect accuracy - 90% is good enough. We can thus use the
260260
# older and smaller MobileNet V1 architecture. But this *still* won't be small enough - by default,
261-
# MobileNet V1 with 224x224 inputs and depth 1.0 takes ~50 MB to just **store**. To reduce the size
261+
# MobileNet V1 with 224x224 inputs and alpha 1.0 takes ~50 MB to just **store**. To reduce the size
262262
# of the model, there are three knobs we can turn. First, we can reduce the size of the input images
263-
# from 224x224 to 96x96 or 64x64, and Keras makes it easy to do this. We can also reduce the **depth**
264-
# of the model, from 1.0 to 0.25. And if we were really strapped for space, we could reduce the
263+
# from 224x224 to 96x96 or 64x64, and Keras makes it easy to do this. We can also reduce the **alpha**
264+
# of the model, from 1.0 to 0.25, which downscales the width of the network (and the number of
265+
# filters) by a factor of four. And if we were really strapped for space, we could reduce the
265266
# number of **channels** by making our model take grayscale images instead of RGB ones.
266267
#
267-
# In this tutorial, we will use an RGB 64x64 input image and 0.25 depth scale. This is not quite
268+
# In this tutorial, we will use an RGB 64x64 input image and alpha 0.25. This is not quite
268269
# ideal, but it allows the finished model to fit in 192 KB of RAM, while still letting us perform
269-
# transfer learning using the official Tensorflow source models (if we used depth scale <0.25 or
270-
# a grayscale input, we wouldn't be able to do this).
270+
# transfer learning using the official Tensorflow source models (if we used alpha <0.25 or a
271+
# grayscale input, we wouldn't be able to do this).
271272
#
272273
# What is Transfer Learning?
273274
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -369,14 +370,12 @@
369370
# the conversion. By default, TFLite keeps the inputs and outputs of our model as floats, so we must
370371
# explicitly tell it to avoid this behavior.
371372

372-
converter = tf.lite.TFLiteConverter.from_keras_model(model)
373-
374-
375373
def representative_dataset():
376374
for image_batch, label_batch in full_dataset.take(10):
377375
yield [image_batch]
378376

379377

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

565564
shutil.rmtree(f"{FOLDER}/models/project/build", ignore_errors=True)
565+
# sphinx_gallery_start_ignore
566+
arduino_project = MagicMock()
567+
# sphinx_gallery_end_ignore
566568
arduino_project.build()
567569
print("Compilation succeeded!")
568570

tests/scripts/ci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def docs(
260260
"tlcpack-sphinx-addon==0.2.1",
261261
"synr==0.5.0",
262262
"image==1.5.33",
263-
"git+https://github.com/guberti/sphinx-gallery.git@ipynb-include-bash",
263+
"git+https://github.com/sphinx-gallery/sphinx-gallery.git",
264264
"sphinx-rtd-theme==1.0.0",
265265
"matplotlib==3.3.4",
266266
"commonmark==0.9.1",

0 commit comments

Comments
 (0)