2019年5月1日 星期三

Jetson Nano圖片識別範例

臺灣黑熊辨識....

https://devblogs.nvidia.com/jetson-nano-ai-computing/
此頁面下的Hello AI world提供許多範例,下例先以圖片識別(Coding your own image recognition)做Demo;


先下載jetson-inference整個專案並編譯,
參閱https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-repo.md



接著把jetson-inference/examples/下的my-recognition資料夾整個複製回家目錄下
~$ cp -R ~/jetson-inference/examples/my-recognition/ ~/
進入剛複製的my-recognition下會有6個檔,其中三個為示範用圖片

接著在my-recognition下build example
~$ cmake .
~$ make

到此大致上已經完成,接著先來識別範例內的北極熊是否能判別出來:


~$ ./my-recognition polar_bear.jpg



















顯示結果為
class 0296 - 0.999999  (ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus)

image is recognized as 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus' (class #296) with 99.999878% confidence

我們再拿一張臺灣黑熊的照片來試試
tseng@jetsonnano:~/my-recognition$ ./my-recognition  bb1.jpg
loaded image  bb1.jpg  (184 x 274)  806656 bytes
[cuda]  cudaAllocMapped 806656 bytes, CPU 0x100c30000 GPU 0x100c30000

imageNet -- loading classification network model from:
         -- prototxt     networks/googlenet.prototxt
         -- model        networks/bvlc_googlenet.caffemodel
         -- class_labels networks/ilsvrc12_synset_words.txt
         -- input_blob   'data'
         -- output_blob  'prob'
         -- batch_size   2

[TRT]  TensorRT version 5.0.6
[TRT]  detected model format - caffe  (extension '.caffemodel')
[TRT]  desired precision specified for GPU: FASTEST
[TRT]  requested fasted precision for device GPU without providing valid calibrator, disabling INT8
[TRT]  native precisions detected for GPU:  FP32, FP16
[TRT]  selecting fastest native precision for GPU:  FP16
[TRT]  attempting to open engine cache file /usr/local/bin/networks/bvlc_googlenet.caffemodel.2.1.GPU.FP16.engine
[TRT]  loading network profile from engine cache... /usr/local/bin/networks/bvlc_googlenet.caffemodel.2.1.GPU.FP16.engine
[TRT]  device GPU, /usr/local/bin/networks/bvlc_googlenet.caffemodel loaded
[TRT]  device GPU, CUDA engine context initialized with 2 bindings
[TRT]  binding -- index   0
               -- name    'data'
               -- type    FP32
               -- in/out  INPUT
               -- # dims  3
               -- dim #0  3 (CHANNEL)
               -- dim #1  224 (SPATIAL)
               -- dim #2  224 (SPATIAL)
[TRT]  binding -- index   1
               -- name    'prob'
               -- type    FP32
               -- in/out  OUTPUT
               -- # dims  3
               -- dim #0  1000 (CHANNEL)
               -- dim #1  1 (SPATIAL)
               -- dim #2  1 (SPATIAL)
[TRT]  binding to input 0 data  binding index:  0
[TRT]  binding to input 0 data  dims (b=2 c=3 h=224 w=224) size=1204224
[cuda]  cudaAllocMapped 1204224 bytes, CPU 0x100f30000 GPU 0x100f30000
[TRT]  binding to output 0 prob  binding index:  1
[TRT]  binding to output 0 prob  dims (b=2 c=1000 h=1 w=1) size=8000
[cuda]  cudaAllocMapped 8000 bytes, CPU 0x101060000 GPU 0x101060000
device GPU, /usr/local/bin/networks/bvlc_googlenet.caffemodel initialized.
[TRT]  networks/bvlc_googlenet.caffemodel loaded
imageNet -- loaded 1000 class info entries
networks/bvlc_googlenet.caffemodel initialized.
class 0295 - 0.730006  (American black bear, black bear, Ursus americanus, Euarctos americanus)
class 0297 - 0.231508  (sloth bear, Melursus ursinus, Ursus ursinus)
class 0367 - 0.011617  (chimpanzee, chimp, Pan troglodytes)
image is recognized as 'American black bear, black bear, Ursus americanus, Euarctos americanus' (class #295) with 73.000565% confidence
結果辨識為黑熊...
換石虎試試...
tseng@jetsonnano:~/my-recognition$ ./my-recognition  st1.jpg
loaded image  st1.jpg  (273 x 184)  803712 bytes
[cuda]  cudaAllocMapped 803712 bytes, CPU 0x100c30000 GPU 0x100c30000

imageNet -- loading classification network model from:
         -- prototxt     networks/googlenet.prototxt
         -- model        networks/bvlc_googlenet.caffemodel
         -- class_labels networks/ilsvrc12_synset_words.txt
         -- input_blob   'data'
         -- output_blob  'prob'
         -- batch_size   2

[TRT]  TensorRT version 5.0.6
[TRT]  detected model format - caffe  (extension '.caffemodel')
[TRT]  desired precision specified for GPU: FASTEST
[TRT]  requested fasted precision for device GPU without providing valid calibrator, disabling INT8
[TRT]  native precisions detected for GPU:  FP32, FP16
[TRT]  selecting fastest native precision for GPU:  FP16
[TRT]  attempting to open engine cache file /usr/local/bin/networks/bvlc_googlenet.caffemodel.2.1.GPU.FP16.engine
[TRT]  loading network profile from engine cache... /usr/local/bin/networks/bvlc_googlenet.caffemodel.2.1.GPU.FP16.engine
[TRT]  device GPU, /usr/local/bin/networks/bvlc_googlenet.caffemodel loaded
[TRT]  device GPU, CUDA engine context initialized with 2 bindings
[TRT]  binding -- index   0
               -- name    'data'
               -- type    FP32
               -- in/out  INPUT
               -- # dims  3
               -- dim #0  3 (CHANNEL)
               -- dim #1  224 (SPATIAL)
               -- dim #2  224 (SPATIAL)
[TRT]  binding -- index   1
               -- name    'prob'
               -- type    FP32
               -- in/out  OUTPUT
               -- # dims  3
               -- dim #0  1000 (CHANNEL)
               -- dim #1  1 (SPATIAL)
               -- dim #2  1 (SPATIAL)
[TRT]  binding to input 0 data  binding index:  0
[TRT]  binding to input 0 data  dims (b=2 c=3 h=224 w=224) size=1204224
[cuda]  cudaAllocMapped 1204224 bytes, CPU 0x100f30000 GPU 0x100f30000
[TRT]  binding to output 0 prob  binding index:  1
[TRT]  binding to output 0 prob  dims (b=2 c=1000 h=1 w=1) size=8000
[cuda]  cudaAllocMapped 8000 bytes, CPU 0x101060000 GPU 0x101060000
device GPU, /usr/local/bin/networks/bvlc_googlenet.caffemodel initialized.
[TRT]  networks/bvlc_googlenet.caffemodel loaded
imageNet -- loaded 1000 class info entries
networks/bvlc_googlenet.caffemodel initialized.
class 0038 - 0.010387  (banded gecko)
class 0285 - 0.100883  (Egyptian cat)
class 0287 - 0.838111  (lynx, catamount)
class 0288 - 0.023775  (leopard, Panthera pardus)
image is recognized as 'lynx, catamount' (class #287) with 83.811073% confidence
辨識為"山貓"...




2019年4月29日 星期一

簡單GPIO輸出測試

為了方便安裝Jetson.GPIO,先在環境中把pip裝上

接著安裝Jetson.GPIO(https://pypi.org/project/Jetson.GPIO/)


pip search後,目前最新版為0.1.2

key上 pip3 install Jetson.GPIO,即開始安裝
上圖顯示Jetson.GPIO已存在




先簡單測試一下輸出(18腳LED間隔1秒閃爍):
vi gpio_test1.py


程式編好後,退出vi,接著key上 python3 gpio_test1.py
上圖中警告訊息是因為GPIO18腳剛剛已被設定使用,程式退出時未做cleanup(),故提出警告
LED執行如下



之後可再使用原本內含的範例檔simple_out.py測試
範例程式位於/opt/nvidia/jetson-gpio/sample目錄下
程式內容如下(刪除部分註解):







2019年4月26日 星期五

JetsonNano expansion header簡述

Jetson Nano的 40pin 擴充接腳簡述
Header上方印刷說明 

Header下方印刷說明
 

Jetson NanoGPIO接腳使用3.3V level
預設所有的siganl pins都為GPIO,除了下述
pin3(DIO2)=>I2C bus1的SDA
pin5(DIO3)=>I2C bus1的SCL
pin27(DIO0)=>I2C bu0的SDA
ping28(DIO1)=>I2C bus0的SCL
pin8(DIO14)=> UART TX
pin10(DIO15)=>UART RX








GPIO no.
pin
pin
GPIO no.

3.3V

1
2

5V
I2C bus1 SDA
2
3
4

5V
I2C bus1 SCL
3
5
6

GND

4
7
8
14
TX
GND

9
10
15
RX

17
11
12
18


27
13
14

GND

22
15
16
23

3.3V

17
18
24


10
19
20

GND

9
21
22
25


11
23
24
8

GND

25
26
7

I2C bus0 SDA
0
27
28
1
I2C bus0 SCL

5
29
30

GND

6
31
32
12


13
33
34

GND

19
35
36
16


26
37
38
20

GND

39
40
21








J41 Top layer Header



L4T有提供python library,Jetson.GPIO作為控制GPIO用
此library如同RPi.GPIO。(說明存放於Jetson系統內 , /opt/nvidia/jetson-gpio/doc/README.txt )