網頁

2020年8月31日 星期一

在桌面顯示 主機資訊

參考 Ubuntu 20.04 System Monitoring with Conky widgets, Ubuntu 18.04也可用
$ sudo apt-get install conky-all
開始/Startup Applications
加入 /usr/bin/conky
$ sudo reboot
$ cp /etc/conky/conky.conf ~/.conkyrc
$ vi ~/.conkyrc
conky.config = {
update_interval = 1,
cpu_avg_samples = 2,
net_avg_samples = 2,
out_to_console = false,
override_utf8_locale = true,
double_buffer = true,
no_buffers = true,
text_buffer_size = 32768,
imlib_cache_size = 0,
own_window = true,
own_window_type = 'normal',
own_window_argb_visual = true,
own_window_argb_value = 80,
own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
border_inner_margin = 5,
border_outer_margin = 0,
xinerama_head = 1,
alignment = 'bottom_right',
gap_x = 0,
gap_y = 33,
draw_shades = false,
draw_outline = false,
draw_borders = false,
draw_graph_borders = false,
use_xft = true,
font = 'Ubuntu Mono:size=12',
xftalpha = 0.8,
uppercase = false,
default_color = 'white',
own_window_colour = '#000000',
minimum_width = 300, minimum_height = 0,
alignment = 'top_right',

};
conky.text = [[
${font sans-serif:bold:size=16}${time %Y-%m-%d}${alignr}${time %H:%M:%S}${font}
${font sans-serif:bold:size=10}SYSTEM ${hr 2}
${font sans-serif:normal:size=8}$sysname $kernel $alignr $machine
Host:$alignr$nodename
Uptime:$alignr$uptime
File System: $alignr${fs_type}
Processes: $alignr ${execi 1000 ps aux | wc -l}

${font sans-serif:bold:size=10}CPU ${hr 2}
${font sans-serif:normal:size=8}${execi 1000 grep model /proc/cpuinfo | cut -d : -f2 | tail -1 | sed 's/\s//'}
${font sans-serif:normal:size=8}CPU:${cpugraph cpu0 50}
CPU: ${cpu cpu0}% ${cpubar cpu0}

${font sans-serif:bold:size=10}Nvidia GPU ${hr 2}
${font sans-serif:normal:size=8}${execpi 1000 (nvidia-smi --query-gpu=gpu_name --format=csv,noheader)}
Temperature:${alignr}${execpi 3 (nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader)}°C
Fan Speed:${alignr}${execpi 3 (nvidia-smi --query-gpu=fan.speed --format=csv,noheader)}
Utilization:${alignr}${execpi 3 (nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader)}
Power:${alignr}${execpi 3 (nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits)}/${execpi 10 (nvidia-smi --query-gpu=power.default_limit --format=csv,noheader)}
Memory:${alignr}${execpi 3 (nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits)}/${execpi 10 (nvidia-smi --query-gpu=memory.total --format=csv,noheader)}
${font Courier-New:normal:size=8}PID${alignc}Name${alignr}Memory
${execpi 3 (nvidia-smi -q|tr -d " "|awk -F ":" '/ProcessID/{printf $2"\t";getline;getline;printf "%-28s",substr($2, 1, 28)"\t";getline;printf $2"\n"}')}

${font sans-serif:bold:size=10}MEMORY ${hr 2}
${font sans-serif:normal:size=8}RAM $alignc $mem / $memmax $alignr $memperc%
$membar
SWAP $alignc ${swap} / ${swapmax} $alignr ${swapperc}%
${swapbar}

${font sans-serif:bold:size=10}DISK USAGE ${hr 2}
${font sans-serif:normal:size=8}/ $alignc ${fs_used /} / ${fs_size /} $alignr ${fs_used_perc /}%
${fs_bar /}

${font Ubuntu:bold:size=10}NETWORK ${hr 2}
${font sans-serif:normal:size=8}Local IPs:${alignr}External IP:
${execi 1000 ip a | grep inet | grep -vw lo | grep -v inet6 | cut -d \/ -f1 | sed 's/[^0-9\.]*//g'}  ${alignr}${execi 1000  wget -q -O- http://ipecho.net/plain; echo}
${font sans-serif:normal:size=8}Down: ${downspeed eno1}  ${alignr}Up: ${upspeed eno1} 
${color lightgray}${downspeedgraph eno1 80,130 } ${alignr}${upspeedgraph eno1 80,130 }$color
${font sans-serif:bold:size=10}TOP PROCESSES ${hr 2}
${font sans-serif:normal:size=8}Name $alignr PID   CPU%   MEM%${font sans-serif:normal:size=8}
${top name 1} $alignr ${top pid 1} ${top cpu 1}% ${top mem 1}%
${top name 2} $alignr ${top pid 2} ${top cpu 2}% ${top mem 2}%
${top name 3} $alignr ${top pid 3} ${top cpu 3}% ${top mem 3}%
${top name 4} $alignr ${top pid 4} ${top cpu 4}% ${top mem 4}%
${top name 5} $alignr ${top pid 5} ${top cpu 5}% ${top mem 5}%
${top name 6} $alignr ${top pid 6} ${top cpu 6}% ${top mem 6}%
${top name 7} $alignr ${top pid 7} ${top cpu 7}% ${top mem 7}%
${top name 8} $alignr ${top pid 8} ${top cpu 8}% ${top mem 8}%
${top name 9} $alignr ${top pid 9} ${top cpu 9}% ${top mem 9}%
${top name 10} $alignr ${top pid 10} ${top cpu 10}% ${top mem 10}%
]];


其中花費最多時間的是
nvidia-smi -q|tr -d " "|awk -F ":" '/ProcessID/{printf $2"\t";getline;getline;printf "%-28s",substr($2, 1, 28)"\t";getline;printf $2"\n"}'
增加 Nvidia GPU 資料

2020年8月27日 星期四

學習 How to configure your NVIDIA Jetson Nano for Computer Vision and Deep Learning

參考 How to configure your NVIDIA Jetson Nano for Computer Vision and Deep Learning

更新 system level packages
$ sudo apt-get update
$ sudo apt-get upgrade

安裝 system-level 相關套件
$ sudo apt-get install git
$ sudo apt-get install cmake
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install gfortran
$ sudo apt-get install libhdf5-serial-dev
$ sudo apt-get install hdf5-tools
$ sudo apt-get install python3-dev
$ sudo apt-get install locate
$ sudo apt-get install libfreetype6-dev
$ sudo apt-get install python3-setuptools
$ sudo apt-get install protobuf-compiler
$ sudo apt-get install libprotobuf-dev
$ sudo apt-get install openssl
$ sudo apt-get install libssl-dev
$ sudo apt-get install libcurl4-openssl-dev
$ sudo apt-get install cython3
$ sudo apt-get install libxml2-dev
$ sudo apt-get install libxslt1-dev

2020年8月25日 星期二

Jetson Nano darknet

參考 Nvidia Jetson Nano 使用心得

$ git clone https://github.com/pjreddie/darknet.git
出現下列錯誤
error: 'CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT' undeclared

改為使用
$ git clone https://github.com/AlexeyAB/darknet
$ cd darknet
$ vi Makefile
GPU=1
CUDNN=1
CUDNN_HALF=1
OPENCV=1
LIBSO=1

$ make -j4

參考 AlexeyAB/darknet
cfg 和 weights 由 YOLOv4 model zoo 下載
yolov4-tiny.weights (建議使用)
yolov4-leaky-416.weight
yolov4-mish-416.weight


nano@nano-desktop:~/Data/darknet/darknet.AlexeyAB$ ./darknet detector demo ../cfg/coco.data ../cfg/yolov4-leaky-416.cfg ../weights/yolov4-leaky-416.weights 'nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink'

nano@nano-desktop:~/Data/darknet/darknet.AlexeyAB$ python3 darknet_video.py --weights ../weights/yolov4-leaky-416.weights --data_file ../cfg/coco.data --config_file ../cfg/yolov4-leaky-416.cfg --input 'nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)416, height=(int)416,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink' --ext_output

需要按 Enter 才會進下一個畫面



Jetson Nano 遠端桌面

原先都是使用 x11vnc
參考 vidia Jetson AGX Xavier 設定 VNC

但常常斷線,太不方便了

$ sudo vi /usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml
在 <schema> 的後面增加
    <key name='enabled' type='b'>
      <summary>Enable remote access to the desktop</summary>
      <description>
        If true, allows remote access to the desktop via the RFB
        protocol. Users on remote machines may then connect to the
        desktop using a VNC viewer.
      </description>
      <default>false</default>
    </key>

編譯 Gnome schemas
$ sudo glib-compile-schemas /usr/share/glib-2.0/schemas
桌面/System Settings/Desktop Sharing
勾選 Allow other users to view your desktop
勾選 Allow other users to control your desktop
桌面/搜尋/Startup Applications
按 Add
Name: Vino
Command: /usr/lib/vino/vino-server
Comment: VNC Server
$ gsettings set org.gnome.Vino require-encryption false
$ gsettings set org.gnome.Vino prompt-enabled false
$ sudo reboot

變更桌面解析度
$ sudo xrandr --fb 1280x960


Build OpenCV on Jetson NANO with CUDA CUDNN

參考 How to configure your NVIDIA Jetson Nano for Computer Vision and Deep Learning

make 時出現下列錯誤
error: 'CUDNN_CONVOLUTION_FWD_PREFER_FASTEST' was not declared in this scope
error: 'CUDNN_CONVOLUTION_BWD_PREFER_FASTEST' was not declared in this scope
原因為 OpenCV 4.4 以前,並不支援 CUDNN8.0

CUDNN 8.0 只能在 OpenCV 4.4 才能 build 成功
$ git clone https://github.com/opencv/opencv.git -b 4.4.0 --depth 1
$ git clone https://github.com/opencv/opencv_contrib.git -b 4.4.0 --depth 1


刪除舊的安裝
$ sudo apt purge libopencv-dev libopencv-python libopencv-samples libopencv*
$ sudo apt update

參考 Any OCR model run in Jetson Nano
參考 Installing tesseract 4.0 on Ubuntu 16.04
$ sudo apt install tesseract-ocr libtesseract-dev


$ sudo add-apt-repository ppa:alex-p/tesseract-ocr
$ sudo apt-get update
$ sudo apt-get install libleptonica-dev
$ sudo apt-get install qt5-default
$ sudo apt-get install qtcreator

cmake \
 -D CMAKE_BUILD_TYPE=RELEASE \
 -D CMAKE_INSTALL_PREFIX=/usr/local \
 -D WITH_CUDA=ON \
 -D WITH_CUDNN=ON \
 -D WITH_CUBLAS=ON \
 -D WITH_V4L=ON \
 -D CUDNN_VERSION='8.0' \
 -D CUDNN_INCLUDE_DIR='/usr/include' \
 -D OPENCV_DNN_CUDA=ON \
 -D WITH_GTK=ON \
 -D WITH_QT=ON \
 -D INSTALL_C_EXAMPLES=OFF \
 -D WITH_GSTREAMER=ON \
 -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.4.0/modules/ \
 -D OPENCV_ENABLE_NONFREE=ON \
 -D BUILD_TESTS=OFF \
 -D BUILD_PERF_TESTS=OFF \
 -D BUILD_EXAMPLES=OFF \
 -D INSTALL_PYTHON_EXAMPLES=ON \
 -D PYTHON_EXECUTABLE=$(which python3) \
 -D BUILD_opencv_python2=OFF \
 -D BUILD_opencv_python3=ON \
 -D BUILD_opencv_java=OFF \
 -D PYTHON3_EXECUTABLE=$(which python3) \
 -D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
 -D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
 -D Tesseract_INCLUDE_DIR=/usr/include/tesseract \
 -D Tesseract_LIBRARY=/usr/lib/aarch64-linux-gnu/libtesseract.so \
 -D Lept_LIBRARY=/usr/lib/aarch64-linux-gun/liblept.so \
 -D CUDA_ARCH_PTX="" \
 -D CUDA_ARCH_BIN="5.3,6.2,7.2" \
 -D OPENCV_GENERATE_PKGCONFIG=YES ..

$ make -j4
$ sudo make install
$ sudo ldconfig


$ opencv_version -v

安裝於 python 的 virtualenv 中
nano@nano-desktop:~/envs/py3cv4/lib/python3.6/site-packages$ ln -s /usr/lib/python3/dist-packages/cv2/python-3.6/cv2.cpython-36m-aarch64-linux-gnu.so cv2.so


在 mainwindow.cpp 檔內增加
#include <opencv2/opencv.hpp>
#include <opencv2/cudaimgproc.hpp>


SSD 測試
(py3cv4) nano@nano-desktop:~/Data/opencv/opencv-dnn-gpu-examples$ python opencv-ssd-cuda/ssd_object_detection.py --prototxt opencv-ssd-cuda/MobileNetSSD_deploy.prototxt --model opencv-ssd-cuda/MobileNetSSD_deploy.caffemodel --input example_videos/guitar.mp4 --display 0 --use-gpu=1
[INFO] setting preferable backend and target to CUDA...
[INFO] accessing video stream...
[INFO] elasped time: 34.94
[INFO] approx. FPS: 7.07
(py3cv4) nano@nano-desktop:~/Data/opencv/opencv-dnn-gpu-examples$ python opencv-ssd-cuda/ssd_object_detection.py --prototxt opencv-ssd-cuda/MobileNetSSD_deploy.prototxt --model opencv-ssd-cuda/MobileNetSSD_deploy.caffemodel --input example_videos/guitar.mp4 --display 0
[INFO] accessing video stream...
[INFO] elasped time: 81.08
[INFO] approx. FPS: 3.05

Yolo 測試
(py3cv4) nano@nano-desktop:~/Data/opencv/opencv-dnn-gpu-examples$ python3 opencv-yolo-cuda/yolo_object_detection.py -y opencv-yolo-cuda/yolo-coco -i example_videos/guitar.mp4 --display=0 --use-gpu=0
[INFO] loading YOLO from disk...
[INFO] setting preferable backend and target to CUDA...
[INFO] accessing video stream...
[INFO] elasped time: 212.71
[INFO] approx. FPS: 1.16
(py3cv4) nano@nano-desktop:~/Data/opencv/opencv-dnn-gpu-examples$ python3 opencv-yolo-cuda/yolo_object_detection.py -y opencv-yolo-cuda/yolo-coco -i example_videos/guitar.mp4 --display=0
[INFO] loading YOLO from disk...
[INFO] accessing video stream...
[INFO] elasped time: 1275.95
[INFO] approx. FPS: 0.19

Mask R-CNN 測試
(py3cv4) nano@nano-desktop:~/Data/opencv/opencv-dnn-gpu-examples$ python3 opencv-mask-rcnn-cuda/mask_rcnn_segmentation.py --mask-rcnn opencv-mask-rcnn-cuda/mask-rcnn-coco/ --input example_videos/guitar.mp4 --display=0 --use-gpu=1
[INFO] loading Mask R-CNN from disk...
[INFO] setting preferable backend and target to CUDA...
[INFO] accessing video stream...
[INFO] elasped time: 445.18
[INFO] approx. FPS: 0.55
(py3cv4) nano@nano-desktop:~/Data/opencv/opencv-dnn-gpu-examples$ python3 opencv-mask-rcnn-cuda/mask_rcnn_segmentation.py --mask-rcnn opencv-mask-rcnn-cuda/mask-rcnn-coco/ --input example_videos/guitar.mp4 --display=0
[INFO] loading Mask R-CNN from disk...
[INFO] accessing video stream...
[INFO] elasped time: 4512.29
[INFO] approx. FPS: 0.05

2020年8月24日 星期一

Qt

參考 在Ubuntu中編譯您的第一個Qt程序

安裝
$ sudo apt-get update
$ sudo apt-get install build-essential
$ sudo apt-get install qtcreator
$ sudo apt-get install qt5-default

第一個程式
$ mkdir SampleProject; cd SampleProject
$ vi testmain.cpp
#include <QApplication>
#include <QLabel>
#include <QWidget>

int main(int argc, char *argv[ ])
{
    QApplication app(argc, argv);
    QLabel hello("<center>Welcome to my first Qt program</center>");
    hello.setWindowTitle("My First Qt Program");
    hello.resize(400, 400);
    hello.show();
    return app.exec();
}

$ qmake -project
產生 SampleProject.pro
$ vi SampleProject.pro
檔案後加入下列一行
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
$ qmake SampleProject.pro
產生 Makefile
$ make
產生 SampleProject

2020年8月12日 星期三

Docker 安裝和使用

安裝參考 Install Docker Engine on Ubuntu
命令參考 docker-tutorial

查詢 docker 運行狀態
$ sudo systemctl status docker
將使用者加入 docker group
$ sudo usermod -aG docker ${USER}
確認是否加入 group
$ id -nG

Docker 名詞
Image 影像檔, 唯讀
Container 容器, 執行的影像檔, 可讀寫
Registry, 存放很多 image 地方,如 Docker HubNGC

查詢所有可用命令