This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
projects:farmrobot:nvidia-jetson-tx1 [2020/12/07 19:59] jason |
projects:farmrobot:nvidia-jetson-tx1 [2021/01/10 19:28] (current) jason |
||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ^ User ^ Password | ^ User ^ Password | ||
| | '' | | '' | ||
| + | |||
| + | ===== Running YOLOv5 with on-board CSI camera or external USB camera (Motion JPEG) ===== | ||
| + | |||
| + | Arguments for NVIDIA' | ||
| + | |||
| + | To start YOLOv5' | ||
| + | |||
| + | <file shell> | ||
| + | # On-board CSI camera | ||
| + | python3.8 detect.py --source " | ||
| + | |||
| + | # External USB camera (Motion JPEG) | ||
| + | python3.8 detect.py --source " | ||
| + | </ | ||
| + | |||
| + | <WRAP important> | ||
| + | In the example above, the on-board CSI camera is represented by ''/ | ||
| + | </ | ||
| + | |||
| + | <WRAP info> | ||
| + | See this [[https:// | ||
| + | </ | ||
| + | |||
| + | ===== 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 51: | Line 109: | ||
| 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 142: | ||
| </ | </ | ||
| - | ==== Python 3.8 ==== | + | ==== Installing |
| To install Python 3.8 you first need to make sure that the '' | To install Python 3.8 you first need to make sure that the '' | ||
| Line 85: | Line 167: | ||
| 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 '' | ||
| + | </ | ||
| + | |||