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
~$ 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
辨識為"山貓"...