From c477bfff73abb8b34c08fc3aef442c994349afc0 Mon Sep 17 00:00:00 2001 From: Chitoku YATO Date: Fri, 13 Dec 2019 18:19:08 -0800 Subject: [PATCH 1/7] Add create sdcard image script --- scripts/create-sdcard-image-from-scratch.sh | 75 +++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 scripts/create-sdcard-image-from-scratch.sh diff --git a/scripts/create-sdcard-image-from-scratch.sh b/scripts/create-sdcard-image-from-scratch.sh new file mode 100755 index 00000000..9826dd7a --- /dev/null +++ b/scripts/create-sdcard-image-from-scratch.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +password='jetbot' + +# Keep updating the existing sudo time stamp +sudo -v +while true; do sudo -n true; sleep 120; kill -0 "$$" || exit; done 2>/dev/null & + +# Enable i2c permissions +sudo usermod -aG i2c $USER + +# Install pip and some python dependencies +sudo apt-get update +sudo apt install -y python3-pip python3-pil +sudo pip3 install --upgrade numpy + +# Install the pre-built TensorFlow pip wheel +sudo apt-get update +sudo apt-get install -y libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev +sudo apt-get install -y python3-pip +sudo pip3 install -U pip +sudo pip3 install -U numpy==1.16.1 future==0.17.1 mock==3.0.5 h5py==2.9.0 keras_preprocessing==1.0.5 keras_applications==1.0.6 enum34 futures testresources setuptools protobuf +sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu==1.14.0+nv19.10 + +# Install the pre-built PyTorch pip wheel +wget https://nvidia.box.com/shared/static/phqe92v26cbhqjohwtvxorrwnmrnfx1o.whl -O torch-1.3.0-cp36-cp36m-linux_aarch64.whl +sudo pip3 install numpy torch-1.3.0-cp36-cp36m-linux_aarch64.whl + +# Install torchvision package +git clone https://github.com/pytorch/vision +cd vision +git checkout v0.4.0 +sudo python3 setup.py install + +# Install traitlets (master, to support the unlink() method) +sudo python3 -m pip install git+https://github.com/ipython/traitlets@master + +# Install jupyter lab +sudo apt install -y nodejs npm +sudo pip3 install jupyter jupyterlab +sudo jupyter labextension install @jupyter-widgets/jupyterlab-manager + +jupyter lab --generate-config +#jupyter notebook password +python3 -c "from notebook.auth.security import set_password; set_password('$password', '$HOME/.jupyter/jupyter_notebook_config.json')" + +# install jetbot python module +cd +sudo apt install -y python3-smbus +cd ~/jetbot +sudo apt-get install -y cmake +sudo python3 setup.py install + +# Install jetbot services +cd jetbot/utils +python3 create_stats_service.py +sudo mv jetbot_stats.service /etc/systemd/system/jetbot_stats.service +sudo systemctl enable jetbot_stats +sudo systemctl start jetbot_stats +python3 create_jupyter_service.py +sudo mv jetbot_jupyter.service /etc/systemd/system/jetbot_jupyter.service +sudo systemctl enable jetbot_jupyter +sudo systemctl start jetbot_jupyter + +# Make swapfile +cd +sudo fallocate -l 4G /var/swapfile +sudo chmod 600 /var/swapfile +sudo mkswap /var/swapfile +sudo swapon /var/swapfile +sudo bash -c 'echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab' + +# Copy JetBot notebooks to home directory +cp -r ~/jetbot/notebooks ~/Notebooks + From 246bb5683be0bc15fde6d0291633170bbe79c486 Mon Sep 17 00:00:00 2001 From: John Welsh Date: Thu, 19 Dec 2019 18:31:26 -0800 Subject: [PATCH 2/7] fixed object detector for JP4.3 by giving unique name to plugin. breaks compatibility with other engines using old name --- jetbot/ssd_tensorrt/FlattenConcat.cpp | 2 +- jetbot/ssd_tensorrt/ssd_tensorrt.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jetbot/ssd_tensorrt/FlattenConcat.cpp b/jetbot/ssd_tensorrt/FlattenConcat.cpp index 94b5cfb2..6fb4d148 100644 --- a/jetbot/ssd_tensorrt/FlattenConcat.cpp +++ b/jetbot/ssd_tensorrt/FlattenConcat.cpp @@ -25,7 +25,7 @@ using namespace nvinfer1; namespace { const char* FLATTENCONCAT_PLUGIN_VERSION{"1"}; -const char* FLATTENCONCAT_PLUGIN_NAME{"FlattenConcat_TRT"}; +const char* FLATTENCONCAT_PLUGIN_NAME{"FlattenConcat_TRT_jetbot"}; } // Flattens all input tensors and concats their flattened version together diff --git a/jetbot/ssd_tensorrt/ssd_tensorrt.py b/jetbot/ssd_tensorrt/ssd_tensorrt.py index 53d6cee7..db6e9334 100644 --- a/jetbot/ssd_tensorrt/ssd_tensorrt.py +++ b/jetbot/ssd_tensorrt/ssd_tensorrt.py @@ -177,13 +177,13 @@ def ssd_pipeline_to_uff(checkpoint_path, config_path, boxloc_concat_plugin = gs.create_plugin_node( "boxloc_concat", - op="FlattenConcat_TRT", + op="FlattenConcat_TRT_jetbot", dtype=tf.float32, ) boxconf_concat_plugin = gs.create_plugin_node( "boxconf_concat", - op="FlattenConcat_TRT", + op="FlattenConcat_TRT_jetbot", dtype=tf.float32, ) From 907f0c8c530dbe5740ac4c8e798842dfe07d2ca7 Mon Sep 17 00:00:00 2001 From: Chitoku YATO Date: Fri, 20 Dec 2019 17:27:09 -0800 Subject: [PATCH 3/7] Create run-script-and-save-log.sh --- scripts/run-script-and-save-log.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 scripts/run-script-and-save-log.sh diff --git a/scripts/run-script-and-save-log.sh b/scripts/run-script-and-save-log.sh new file mode 100644 index 00000000..fb129e4b --- /dev/null +++ b/scripts/run-script-and-save-log.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +./create-sdcard-image-from-scratch.sh 2>&1 | tee ~/jetbot-create-sdcard-image.log From 669cfc9474f9a376191a88fa67abb4094db9c5e2 Mon Sep 17 00:00:00 2001 From: jetbot Date: Mon, 23 Dec 2019 11:50:47 -0800 Subject: [PATCH 4/7] Make the script executable --- scripts/run-script-and-save-log.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/run-script-and-save-log.sh diff --git a/scripts/run-script-and-save-log.sh b/scripts/run-script-and-save-log.sh old mode 100644 new mode 100755 From 2ccaa8e0ec2016f8f6323b8c5ba335b7f8323b62 Mon Sep 17 00:00:00 2001 From: John Welsh Date: Wed, 15 Jan 2020 18:56:53 -0800 Subject: [PATCH 5/7] moved TF dependent imports into functions --- jetbot/ssd_tensorrt/ssd_tensorrt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jetbot/ssd_tensorrt/ssd_tensorrt.py b/jetbot/ssd_tensorrt/ssd_tensorrt.py index db6e9334..3fa2f18d 100644 --- a/jetbot/ssd_tensorrt/ssd_tensorrt.py +++ b/jetbot/ssd_tensorrt/ssd_tensorrt.py @@ -1,10 +1,8 @@ import ctypes -import graphsurgeon as gs import numpy as np import os import subprocess import tensorrt as trt -import uff TRT_INPUT_NAME = 'input' TRT_OUTPUT_NAME = 'nms' @@ -86,9 +84,10 @@ def _load_config(config_path): def ssd_pipeline_to_uff(checkpoint_path, config_path, tmp_dir='exported_model'): - + import graphsurgeon as gs from object_detection import exporter import tensorflow as tf + import uff # TODO(@jwelsh): Implement by extending model builders with # TensorRT plugin stubs. Currently, this method uses pattern @@ -224,6 +223,7 @@ def ssd_uff_to_engine(uff_buffer, strict_type_constraints=False, log_level=trt.Logger.INFO): + import uff # create the tensorrt engine with trt.Logger(log_level) as logger, trt.Builder(logger) as builder, \ builder.create_network() as network, trt.UffParser() as parser: From 9a4bfab10b35550e2dccc1d9e96949a8cd1e2546 Mon Sep 17 00:00:00 2001 From: John Welsh Date: Wed, 15 Jan 2020 18:57:45 -0800 Subject: [PATCH 6/7] incremented vers to v0.4.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f714bdbc..f7e6681a 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def build_libs(): setup( name='jetbot', - version='0.3.0', + version='0.4.0', description='An open-source robot based on NVIDIA Jetson Nano', packages=find_packages(), install_requires=[ From cc1112afa7ffc77f7e252f6d244049ee4a839f73 Mon Sep 17 00:00:00 2001 From: John Welsh Date: Wed, 15 Jan 2020 19:17:27 -0800 Subject: [PATCH 7/7] minor fixes to notebooks --- notebooks/collision_avoidance/live_demo.ipynb | 9 +++++++-- notebooks/road_following/live_demo.ipynb | 9 +++++++-- notebooks/road_following/train_model.ipynb | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/notebooks/collision_avoidance/live_demo.ipynb b/notebooks/collision_avoidance/live_demo.ipynb index e0220ebb..bcf67e0b 100644 --- a/notebooks/collision_avoidance/live_demo.ipynb +++ b/notebooks/collision_avoidance/live_demo.ipynb @@ -237,7 +237,12 @@ }, "outputs": [], "source": [ + "import time\n", + "\n", "camera.unobserve(update, names='value')\n", + "\n", + "time.sleep(0.1) # add a small sleep to make sure frames have finished processing\n", + "\n", "robot.stop()" ] }, @@ -302,9 +307,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.7" + "version": "3.6.9" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/notebooks/road_following/live_demo.ipynb b/notebooks/road_following/live_demo.ipynb index dd37d061..dc5d094f 100644 --- a/notebooks/road_following/live_demo.ipynb +++ b/notebooks/road_following/live_demo.ipynb @@ -317,7 +317,12 @@ "metadata": {}, "outputs": [], "source": [ + "import time\n", + "\n", "camera.unobserve(execute, names='value')\n", + "\n", + "time.sleep(0.1) # add a small sleep to make sure frames have finished processing\n", + "\n", "robot.stop()" ] }, @@ -348,9 +353,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.7" + "version": "3.6.9" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/notebooks/road_following/train_model.ipynb b/notebooks/road_following/train_model.ipynb index eaeead33..d705fa99 100644 --- a/notebooks/road_following/train_model.ipynb +++ b/notebooks/road_following/train_model.ipynb @@ -246,7 +246,7 @@ " optimizer.zero_grad()\n", " outputs = model(images)\n", " loss = F.mse_loss(outputs, labels)\n", - " train_loss += loss\n", + " train_loss += float(loss)\n", " loss.backward()\n", " optimizer.step()\n", " train_loss /= len(train_loader)\n", @@ -258,7 +258,7 @@ " labels = labels.to(device)\n", " outputs = model(images)\n", " loss = F.mse_loss(outputs, labels)\n", - " test_loss += loss\n", + " test_loss += float(loss)\n", " test_loss /= len(test_loader)\n", " \n", " print('%f, %f' % (train_loss, test_loss))\n", @@ -293,9 +293,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.7" + "version": "3.6.9" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }