This shows you the differences between two versions of the page.
Next revision | Previous revision Next revision Both sides next revision | ||
projects:farmrobot:nvidia-jetson-tx1 [2020/12/07 19:52] jason created |
projects:farmrobot:nvidia-jetson-tx1 [2021/01/10 02:12] jason |
||
---|---|---|---|
Line 4: | Line 4: | ||
^ User ^ Password | ^ User ^ Password | ||
- | | jetson | + | | '' |
+ | |||
+ | ===== Running YOLOv5 with on-board camera ===== | ||
+ | |||
+ | Arguments for NVIDIA' | ||
+ | |||
+ | To start YOLOv5' | ||
+ | |||
+ | <file shell> | ||
+ | python3.8 detect.py --source " | ||
+ | </ | ||
+ | |||
+ | ===== Current data ===== | ||
+ | |||
+ | ==== On-board camera ==== | ||
+ | |||
+ | <file shell> | ||
+ | sudo apt install -y v4l-utils | ||
+ | </ | ||
+ | |||
+ | <file shell> | ||
+ | v4l2-ctl -d /dev/video0 --list-formats-ext | ||
+ | |||
+ | ioctl: VIDIOC_ENUM_FMT | ||
+ | Index : 0 | ||
+ | Type : Video Capture | ||
+ | Pixel Format: ' | ||
+ | Name : 10-bit Bayer BGBG/GRGR | ||
+ | Size: Discrete 2592x1944 | ||
+ | Interval: Discrete 0.033s (30.000 fps) | ||
+ | Size: Discrete 2592x1458 | ||
+ | Interval: Discrete 0.033s (30.000 fps) | ||
+ | Size: Discrete 1280x720 | ||
+ | Interval: Discrete 0.008s (120.000 fps) | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | |||
+ | ==== Measurements ==== | ||
+ | |||
+ | YOLOv5 (street.mp4): | ||
+ | |||
+ | {{: | ||
===== Setup ===== | ===== Setup ===== | ||
Line 13: | Line 59: | ||
To install the JetPack SDK on the Jetson TX1 you need to download and install [[https:// | To install the JetPack SDK on the Jetson TX1 you need to download and install [[https:// | ||
- | After downloading the .deb file, you need to install it with `apt`: | + | After downloading the '' |
<file shell> | <file shell> | ||
Line 20: | Line 66: | ||
<WRAP important> | <WRAP important> | ||
- | If the installation fails because some dependencies couldn' | + | If the installation fails because some dependencies couldn' |
<file shell> | <file shell> | ||
Line 51: | Line 97: | ||
After the installation finished, disconnect the Jetson TX1 from the host machine. | After the installation finished, disconnect the Jetson TX1 from the host machine. | ||
+ | |||
+ | ==== Mounting external storage to /home ==== | ||
+ | |||
+ | Mount the partition on the SD-card to ''/ | ||
+ | |||
+ | <file shell> | ||
+ | sudo mount / | ||
+ | </ | ||
+ | |||
+ | Change into the ''/ | ||
+ | |||
+ | <file shell> | ||
+ | cd /home | ||
+ | cp -adpR * /mnt | ||
+ | </ | ||
+ | |||
+ | Unmount the partition from ''/ | ||
+ | |||
+ | <file shell> | ||
+ | sudo umount /mnt | ||
+ | </ | ||
+ | |||
+ | Then open the disk utility and go to the mounting settings of the partition on the SD-card. | ||
+ | Set it to automatically mount on ''/ | ||
==== Updating apt packages ==== | ==== Updating apt packages ==== | ||
Line 60: | Line 130: | ||
</ | </ | ||
- | ==== Python 3.8 ==== | + | ==== Installing |
- | To install Python 3.8 you first need to make sure that the software-properties-common package is installed: | + | To install Python 3.8 you first need to make sure that the '' |
<file shell> | <file shell> | ||
Line 68: | Line 138: | ||
</ | </ | ||
- | Then add the deadsnakes PPA to apt, like so: | + | Then add the '' |
<file shell> | <file shell> | ||
Line 74: | Line 144: | ||
</ | </ | ||
- | Afterwards, you can install Python 3.8 via apt: | + | Afterwards, you can install Python 3.8 via '' |
<file shell> | <file shell> | ||
Line 80: | Line 150: | ||
</ | </ | ||
- | Also make sure to have pip for Python 3.X installed: | + | Also make sure to have '' |
<file shell> | <file shell> | ||
sudo apt install -y python3-pip | sudo apt install -y python3-pip | ||
</ | </ | ||
+ | |||
+ | |||
+ | ==== Adding temporary swap space ==== | ||
+ | |||
+ | The next few operations can be very CPU and RAM intensive. | ||
+ | |||
+ | It's possible that the installed 4GB of RAM and pre-configured 2GB of swap space are not enough to handle these operations. That's why you may need to configure additional swap space. | ||
+ | |||
+ | First, check if any additional swap space is already configured by running: | ||
+ | |||
+ | <file shell> | ||
+ | sudo swapon --show | ||
+ | </ | ||
+ | |||
+ | If there' | ||
+ | |||
+ | Create a swap file that allocates enough space (Recommended are an additional 4 - 16GB): | ||
+ | |||
+ | <file shell> | ||
+ | sudo fallocate -l 8G ~/swapfile | ||
+ | </ | ||
+ | |||
+ | Make sure that only superusers are able to read and write the swap file: | ||
+ | |||
+ | <file shell> | ||
+ | sudo chmod 600 ~/swapfile | ||
+ | </ | ||
+ | |||
+ | Then set up a swap area on the swap file and activate it: | ||
+ | |||
+ | <file shell> | ||
+ | sudo mkswap ~/swapfile | ||
+ | |||
+ | sudo swapon ~/swapfile | ||
+ | </ | ||
+ | |||
+ | ==== Building OpenCV from source (with GStreamer support) ==== | ||
+ | |||
+ | Because [[https:// | ||
+ | |||
+ | <WRAP info> | ||
+ | [[https:// | ||
+ | </ | ||
+ | |||
+ | To get started, install the packages that OpenCV with GStreamer support depends on: | ||
+ | |||
+ | <file shell> | ||
+ | sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev | ||
+ | </ | ||
+ | |||
+ | Then, install [[https:// | ||
+ | |||
+ | <file shell> | ||
+ | python3.8 -m pip install --user numpy | ||
+ | </ | ||
+ | |||
+ | After all dependencies are installed, go ahead and clone the [[https:// | ||
+ | |||
+ | <file shell> | ||
+ | git clone https:// | ||
+ | |||
+ | cd opencv | ||
+ | |||
+ | # General | ||
+ | git checkout < | ||
+ | |||
+ | # OpenCV 4.5.0 | ||
+ | git checkout 4.5.0 | ||
+ | </ | ||
+ | |||
+ | Before you can start building OpenCV, create a ''/ | ||
+ | |||
+ | <file shell> | ||
+ | mkdir build | ||
+ | |||
+ | cd build | ||
+ | </ | ||
+ | |||
+ | Then, use '' | ||
+ | |||
+ | <file shell> | ||
+ | cmake -D CMAKE_BUILD_TYPE=RELEASE \ | ||
+ | -D INSTALL_PYTHON_EXAMPLES=ON \ | ||
+ | -D INSTALL_C_EXAMPLES=OFF \ | ||
+ | -D PYTHON_EXECUTABLE=$(which python3.8) \ | ||
+ | -D BUILD_opencv_python2=OFF \ | ||
+ | -D CMAKE_INSTALL_PREFIX=$(python3.8 -c “import sys; print(sys.prefix)”) \ | ||
+ | -D PYTHON3_EXECUTABLE=$(which python3.8) \ | ||
+ | -D PYTHON3_INCLUDE_DIR=$(python3.8 -c “from distutils.sysconfig import get_python_inc; | ||
+ | -D PYTHON3_PACKAGES_PATH=$(python3.8 -c “from site import getsitepackages; | ||
+ | -D WITH_GSTREAMER=ON \ | ||
+ | -D BUILD_EXAMPLES=ON .. | ||
+ | </ | ||
+ | |||
+ | It is important to check the resulting output. Check if the output contains the following important bits: | ||
+ | |||
+ | <file shell> | ||
+ | ... | ||
+ | |||
+ | GStreamer: | ||
+ | |||
+ | ... | ||
+ | |||
+ | Python3: | ||
+ | Interpreter: | ||
+ | Libraries: | ||
+ | numpy: | ||
+ | install path: < | ||
+ | |||
+ | ... | ||
+ | </ | ||
+ | |||
+ | If everything went well, you can go ahead and build it: | ||
+ | |||
+ | <file shell> | ||
+ | sudo make -j$(nproc) | ||
+ | </ | ||
+ | |||
+ | When the build is finished, install it: | ||
+ | |||
+ | <file shell> | ||
+ | sudo make install | ||
+ | </ | ||
+ | |||
+ | ==== Building PyTorch and Torchvision from source ==== | ||
+ | |||
+ | At the time of writing this documentation there are no pre-built wheels of [[https:// | ||
+ | |||
+ | <WRAP info> | ||
+ | Both Python 3.8 or later and [[https:// | ||
+ | </ | ||
+ | |||
+ | <WRAP important> | ||
+ | You should first check the [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | </ | ||
+ | |||
+ | First, make sure that you have '' | ||
+ | |||
+ | <file shell> | ||
+ | sudo apt install -y python3.8-dev | ||
+ | </ | ||
+ | |||
+ | Then clone the official PyTorch repository on GitHub with the branch of the version you want to build and change into the created directory: | ||
+ | |||
+ | <file shell> | ||
+ | # General | ||
+ | git clone --recursive --branch < | ||
+ | |||
+ | cd pytorch | ||
+ | |||
+ | # PyTorch 1.7.0 | ||
+ | git clone --recursive --branch 1.7 https:// | ||
+ | </ | ||
+ | |||
+ | Before you can build PyTorch, you first need to install all its dependencies: | ||
+ | |||
+ | <file shell> | ||
+ | python3.8 -m pip install --user -r requirements.txt | ||
+ | </ | ||
+ | |||
+ | If all dependencies are installed, you can go ahead and build PyTorch: | ||
+ | |||
+ | <file shell> | ||
+ | python3.8 setup.py install --user | ||
+ | </ | ||
+ | |||
+ | Once PyTorch itself is installed, you can build Torchvision from source. | ||
+ | |||
+ | First, install all libraries that Torchvision needs: | ||
+ | |||
+ | <file shell> | ||
+ | sudo apt install -y libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev | ||
+ | </ | ||
+ | |||
+ | The version of Torchvision that is needed depends on the version of PyTorch that is installed. At the time of writing Torchvision 0.8.1 is needed for PyTorch 1.7.0. | ||
+ | |||
+ | Then clone the official Torchvision repository on GitHub with the branch of the version you want to build and change into the created directory: | ||
+ | |||
+ | <file shell> | ||
+ | # General | ||
+ | git clone --branch < | ||
+ | |||
+ | cd torchvision | ||
+ | |||
+ | # Torchvision 0.8.1 | ||
+ | git clone --branch v0.8.1 https:// | ||
+ | </ | ||
+ | |||
+ | To build Torchvision, | ||
+ | |||
+ | <file shell> | ||
+ | # General | ||
+ | export BUILD_VERSION=< | ||
+ | |||
+ | # Torchvision 0.8.1 | ||
+ | export BUILD_VERSION=0.8.1 | ||
+ | </ | ||
+ | |||
+ | Then build Torchvision: | ||
+ | |||
+ | <file shell> | ||
+ | python3.8 setup.py install --user | ||
+ | </ | ||
+ | |||
+ | ==== Installing YOLOv5 ==== | ||
+ | |||
+ | Clone our implementation of YOLOv5 from the GitLab repository: | ||
+ | |||
+ | <file shell> | ||
+ | git clone https:// | ||
+ | </ | ||
+ | |||
+ | Then change the directory into the local repository and clone the official [[https:// | ||
+ | |||
+ | <file shell> | ||
+ | cd farm-robot-yolov5 | ||
+ | |||
+ | git clone https:// | ||
+ | </ | ||
+ | |||
+ | To get ready, install all the dependencies one by one: | ||
+ | |||
+ | <file shell> | ||
+ | python3.8 -m pip install --user < | ||
+ | </ | ||
+ | |||
+ | <WRAP important> | ||
+ | Installing all dependencies at once using | ||
+ | |||
+ | <file shell> | ||
+ | python3.8 -m pip install --user -r requirements.txt | ||
+ | </ | ||
+ | |||
+ | can result in errors due to how Python dependencies are installed using the '' | ||
+ | </ | ||
+ |