Jetson Nano
基本設定
使用安裝Jetson Nano with Ubuntu 20.04 OS image
https://github.com/Qengineering/Jetson-Nano-Ubuntu-20-image
更改預設python
cd /usr/bin
sudo rm python
sudo ln -s python3.8 python
sudo apt update
pip3 install --upgrade pip
增加SWAP
#建立檔案
sudo fallocate -l 8G /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'
#驗證是否啟動
sudo swapon --show
sudo free -h
確認CUDA
nvcc -V
安裝YoloV8
pip install ultralytics
pip uninstall opencv-python
安裝OpenCV
pip install numpy==1.23.1
https://qengineering.eu/install-opencv-on-jetson-nano.html
測試opencv
>>> import cv2
>>> cv2.__version__
檢查有沒有 support CUDA & GStreamer
>>>print(cv2.getBuildInformation())
切換開機模式
# 開啟終端機模式
sudo systemctl set-default multi-user.target
# 開啟桌面模式
sudo systemctl set-default graphical.target
# 查看當前的模式
sudo systemctl get-default
調整功耗模式
# 鎖住功率使其不過載
sudo jetson_clocks
# 顯示當前模式
sudo nvpmodel -q
# 預設為高效能模式(10W),此功率需用 DC 5V 4A 供電,不然會突然關機
sudo nvpmodel -m0
# 若使用 Micro-USB 供電需切換到 5W 模式
sudo nvpmodel -m1
設定風扇
sudo touch /etc/rc.local
sudo chmod u+x /etc/rc.local
vi /etc/rc.local
寫入rc.local
sleep 10
sudo /usr/bin/jetson_clocks
sudo sh -c 'echo 255 > /sys/devices/pwm-fan/target_pwm'
安裝輸入法
$ sudo apt install ibus-pinyin ibus-chewing
#介面新增中文
點選「Setting -> Language Support」-> 「install / remove language」,勾選「Chinese(traditional)」,安裝中文介面,安裝好後「中文(台灣)」拖曳到最上方,選擇「Apply System-Wide」。
#設定輸入法
執行「ibus-setup」,設定輸入法的切換方式,與輸入法選chinese增加chewing(新酷音)
固定IP Address
#vi /etc/network/interfaces
auto wlan0
iface wlan0 inet static
address 192.168.3.241
netmask 255.255.255.0
gateway 192.168.3.254
wpa-ssid [wifi-ssid]
wpa-psk [wifipasswd]
XRDP 遠端桌面
安裝tightvncserver跟xrdp套件,重啟Jetson Nano
sudo apt update
sudo apt install tightvncserver xrdp
sudo reboot
安裝xubuntu-desktop
sudo apt install xubuntu-desktop
echo xfce4-session >~/.xsession
重啟xrdp服務
sudo service xrdp restart
參考資料:
https://blog.cavedu.com/2019/12/19/jetson-nano-remote-desktop-windows-mac-osx/
掛載NAS
在/etc/fastab加入下方一行:
//[NAS IP]/[資料夾] /home/[掛載路徑] cifs username=[帳號],password=[密碼],uid=[uid],gid=[gid],sec=ntlm,user_xattr 0 0
執行sudo mount -a重新執行fstab
安裝Archiconda
echo ". /home/jetbot/archiconda3/etc/profile.d/conda.sh" >> ~/.bashrc
安裝常用套件
Python套件的AppStore: https://pypi.org/
PS.安裝matplotlib之前,先移除內建的python3-matplotlib:sudo apt remove python3-matplotlib
重要套件:pip3 install -U numpy==1.19.4 protobuf==3.3.0 cython pillow scipy
matplotlib==3.3.2
機器學習:pip3 install scikit-learn cvzone
網路爬蟲:pip3 install -U requests beautifulsoup4 selenium pandas
若要在虛擬環境下使用上述套件,請在activate檔案中加入:
系統安裝的套件:export PYTHONPATH=/usr/lib/python3.6/dist-packages:$PYTHONPATH
使用者安裝的套件:export PYTHONPATH=/home/jetbot/.local/lib/python3.6/site-packages:$PYTHONPATH
安裝opencv
如果用pip安裝opencv-python,無法使用CUDA
移除原有的opencv
sudo apt purge *libopencv*
檢查是否有移除
pkg-config opencv --modversion
顯示CUDA位置
sudo sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf"
sudo ldconfig
安裝第三方套件
sudo apt install build-essential cmake git unzip pkg-config
sudo apt install libjpeg-dev libpng-dev libtiff-dev
sudo apt install libavcodec-dev libavformat-dev libswscale-dev
sudo apt install libgtk2.0-dev libcanberra-gtk* libgtkglextmm-x11-1.2-dev
sudo apt install python3-dev python3-numpy python3-pip
sudo apt install libxvidcore-dev libx264-dev libgtk-3-dev
sudo apt install libtbb2 libtbb-dev libdc1394-22-dev
sudo apt install gstreamer1.0-tools libv4l-dev v4l-utils
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt install libavresample-dev libvorbis-dev libxine2-dev
sudo apt install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt install libopenblas-dev libatlas-base-dev libblas-dev
sudo apt install liblapack-dev libeigen3-dev gfortran
sudo apt install libhdf5-dev protobuf-compiler v4l-utils
sudo apt install libprotobuf-dev libgoogle-glog-dev libgflags-dev
sudo apt install tesseract-ocr libtesseract-dev libleptonica-dev
下載並解壓OpenCV
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.7.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.7.0.zip
unzip opencv.zip
unzip opencv_contrib.zip
mv opencv-4.7.0 opencv
mv opencv_contrib-4.7.0 opencv_contrib
rm opencv.zip
rm opencv_contrib.zip
建立make
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
-D WITH_OPENCL=OFF \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=5.3 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=ON \
-D WITH_CUBLAS=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_NEON=ON \
-D WITH_QT=OFF \
-D WITH_OPENMP=ON \
-D WITH_OPENGL=ON \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=/usr/bin/python3.6 \
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF ..
開始編譯
make -j4
安裝
sudo rm -rf /usr/include/opencv4/opencv2
sudo make install
sudo ldconfig
測試opencv
>>> import cv2
>>> cv2.__version__
檢查有沒有 support CUDA & GStreamer
>>>print(cv2.getBuildInformation())
改回dphys-swapfile
刪除安裝檔
sudo rm -rf ~/opencv
sudo rm -rf ~/opencv_contrib
link到虛擬環境
cd ~/[venv_name]/lib/python3.6/site-packages/
ln -s /usr/lib/python3.6/dist-packages/cv2/python-3.6/cv2.cpython-36m-aarch64-linux-gnu.so cv2.so
安裝jetson inference
更新相依套件
sudo apt-get update
sudo apt-get install git cmake libpython3-dev python3-numpy
下載:
git clone https://github.com/dusty-nv/jetson-inference
cd jetson-inference
git submodule update --init
編譯:
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig
下載模型檔:
cd jetson-inference/tools
./download-models.sh
官方網站:
安裝CSI相機
#安裝套件
$sudo apt install v4l-utils
#列出攝影機
$v4l2-ctl --list-devices
#攝影機支援的格式
$v4l2-ctl --list-formats-ext
安裝jetbot
sudo usermod -aG i2c [username]
sudo usermod -aG gpio [username]
sudo chmod 777 /dev/ttyTHS1
啟動
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
關閉
sudo systemctl disable jetbot_stats
使用 Jupyter lab
1. 更新 pip3 並安裝 jupyter lab
pip install --upgrade pip
pip install jupyter jupyterlab
sudo reboot
2. 生成 jupyter lab 配置文件
jupyter lab --generate-config
vi ~/.jupyter/jupyter_lab_config.py
修改
c.ServerApp.allow_origin = '*'
c.ServerApp.ip = '0.0.0.0'
3. 設置 jupyter notebook 密碼
jupyter-lab password
設置完後,密碼會存到
~/.jupyter/jupyter_server_config.json
4. 設定開機自動啟動 jupyter lab,創建 jupyter.service 文件
sudo vi /etc/systemd/system/jupyter.service
加入
[Unit]
Description=Jupyter Notebook
[Service]
Type=simple
User=[username]
ExecStart=/home/[username]/.local/bin/jupyter-lab --port 8888 --no-browser
WorkingDirectory=/home/[username]/
[Install]
WantedBy=default.target
5.運行 jupyter
執行以下命令啟動服務
自動啟動
sudo systemctl enable jupyter
sudo systemctl start jupyter
#關閉:sudo systemctl disable jupyter
手動啟動
~/.local/bin/jupyter-lab --port 8888 --no-browser
檢查服務是否有運行
sudo systemctl status jupyter
6.加入虛擬環境到jupyter
安裝ipykernel
pip3 insall ipykernel
加入虛擬環境
sudo python -m ipykernel install --name <venv_name>
安裝jetcam
git clone https://github.com/NVIDIA-AI-IOT/jetcam
cd jetcam
sudo python3 setup.py install
sudo免密碼
sudo visudo
%sudo ALL=(ALL:ALL) NOPASSWD:ALL
備份SD卡
查看SD卡掛載在哪裡
lsblk
備份前先sync
sync
安裝dc3dd
sudo apt install dc3dd
將SD卡寫成img檔
sudo dc3dd if=/dev/mmcblk0 of=[USB掛載路徑]/myimg.img
相關資源
Jetson Community Projects:https://developer.nvidia.com/embedded/community/jetson-projects
Jetson_Zoo:https://elinux.org/Jetson_Zoo