Hello AI Worldを試す - JETSON NANO 開発者キット その2

JETSON NANO 開発者キット を試す その1 の続きです

とりあえずなにかしたいわけですが、Hello AI World として紹介されているやつが便利そう。

github.com

jetson-inference

ドキュメントに従って、Using the Console Program on Jetson まで実行。

Classifying Images with ImageNet

何やら、ImageNet を使用した Classifying らしいです。

~/jetson-inference/build/aarch64/bin$ ./imagenet-console orange_0.jpg output_0.jpg
imagenet-console
  args (3):  0 [./imagenet-console]  1 [orange_0.jpg]  2 [output_0.jpg]  


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]  layer network time - 141.518982 ms
class 0950 - 0.978908  (orange)
class 0951 - 0.020961  (lemon)
imagenet-console:  'orange_0.jpg' -> 97.89076% class #950 (orange)
loaded image  fontmapA.png  (256 x 512)  2097152 bytes
[cuda]  cudaAllocMapped 2097152 bytes, CPU 0x1048a0000 GPU 0x1048a0000
[cuda]  cudaAllocMapped 8192 bytes, CPU 0x100f62000 GPU 0x100f62000
imagenet-console:  attempting to save output image to 'output_0.jpg'
imagenet-console:  completed saving 'output_0.jpg'

shutting down...

f:id:pongsuke:20190419153340j:plain

97%の確率で、オレンジだそうですよ。

Locating Object Coordinates using DetectNet

つぎは、学習済みの DetectNet-COCO-Dog model を使用した、ディテクションです。

$ ./detectnet-console dog_1.jpg output_1.jpg coco-dog
detectnet-console
  args (4):  0 [./detectnet-console]  1 [dog_1.jpg]  2 [output_1.jpg]  3 [coco-dog]  


detectNet -- loading detection network model from:
          -- prototxt     networks/DetectNet-COCO-Dog/deploy.prototxt
          -- model        networks/DetectNet-COCO-Dog/snapshot_iter_38600.caffemodel
          -- input_blob   'data'
          -- output_cvg   'coverage'
          -- output_bbox  'bboxes'
          -- mean_pixel   0.000000
          -- class_labels networks/DetectNet-COCO-Dog/class_labels.txt
          -- threshold    0.500000
          -- batch_size   2

[TRT]  TensorRT version 5.0.6
 ・・・
[TRT]  layer network time - 371.817322 ms
detectnet-console:  finished processing network  (1555656574352)
2 bounding boxes detected
detected obj 0  class #0 (dog)  confidence=0.886617
bounding box 0  (1258.875000, 240.310547)  (1672.687500, 563.941406)  w=413.812500  h=323.630859
detected obj 1  class #0 (dog)  confidence=0.502083
bounding box 1  (594.562500, 328.482422)  (1016.437500, 584.718750)  w=421.875000  h=256.236328
detectnet-console:  writing 1920x1080 image to 'output_1.jpg'
detectnet-console:  successfully wrote 1920x1080 image to 'output_1.jpg'

shutting down...

f:id:pongsuke:20190419155014j:plain

Dog を2つ検出していて、その位置を矩形で出していますね。

Multi-class Object Detection Models

$ ./detectnet-console peds-003.jpg output-3.jpg multiped

 ...
detectnet-console:  finished processing network  (1555657903767)
6 bounding boxes detected
detected obj 0  class #0 (person)  confidence=0.547767
bounding box 0  (382.875000, -127.316528)  (837.625000, 583.328979)  w=454.750000  h=710.645508
detected obj 1  class #0 (person)  confidence=0.671255
bounding box 1  (-6.250000, -5.668457)  (218.250000, 577.884277)  w=224.500000  h=583.552734
detected obj 2  class #0 (person)  confidence=0.554531
bounding box 2  (870.500000, 72.794922)  (989.937500, 452.805298)  w=119.437500  h=380.010376
detected obj 3  class #1 (baggage)  confidence=0.718298
bounding box 3  (681.246094, 263.098450)  (761.109375, 410.105408)  w=79.863281  h=147.006958
detected obj 4  class #1 (baggage)  confidence=0.967225
bounding box 4  (925.593750, 269.661926)  (998.937500, 432.219849)  w=73.343750  h=162.557922
detected obj 5  class #1 (baggage)  confidence=0.979315
bounding box 5  (148.437500, 288.233582)  (323.406250, 522.094727)  w=174.968750  h=233.861145
detectnet-console:  writing 1024x611 image to 'output-3.jpg'
detectnet-console:  successfully wrote 1024x611 image to 'output-3.jpg'

shutting down...

f:id:pongsuke:20190419161342j:plain

GPU 使用率

GPU使用率については、tegrastats Utility を使えとのこと。

$ tegrastats 
RAM 1097/3963MB (lfb 271x4MB) CPU [11%@102,10%@102,6%@102,3%@102] EMC_FREQ 0% GR3D_FREQ 0% PLL@40C CPU@44C PMIC@100C GPU@42C AO@48.5C thermal@43C POM_5V_IN 1248/1248 POM_5V_GPU 0/0 POM_5V_CPU 166/166
RAM 1110/3963MB (lfb 271x4MB) CPU [9%@1428,3%@1428,1%@1428,2%@1428] EMC_FREQ 0% GR3D_FREQ 2% PLL@40.5C CPU@44C PMIC@100C GPU@40C AO@49C thermal@43C POM_5V_IN 2514/1881 POM_5V_GPU 82/41 POM_5V_CPU 823/494
RAM 1342/3963MB (lfb 263x4MB) CPU [8%@1428,97%@1428,7%@1428,6%@1428] EMC_FREQ 0% GR3D_FREQ 6% PLL@41C CPU@45C PMIC@100C GPU@40.5C AO@49.5C thermal@42.5C POM_5V_IN 3317/2359 POM_5V_GPU 163/81 POM_5V_CPU 1226/738
RAM 1474/3963MB (lfb 263x4MB) CPU [8%@1428,96%@1428,6%@1428,6%@1428] EMC_FREQ 0% GR3D_FREQ 0% PLL@41C CPU@44.5C PMIC@100C GPU@40.5C AO@49.5C thermal@42.75C POM_5V_IN 2716/2448 POM_5V_GPU 82/81 POM_5V_CPU 903/779
RAM 1692/3963MB (lfb 250x4MB) CPU [7%@1428,8%@1428,12%@1428,86%@1428] EMC_FREQ 0% GR3D_FREQ 33% PLL@41C CPU@45C PMIC@100C GPU@40.5C AO@49C thermal@43C POM_5V_IN 2917/2542 POM_5V_GPU 123/90 POM_5V_CPU 1025/828
RAM 1711/3963MB (lfb 241x4MB) CPU [8%@403,71%@403,7%@403,5%@403] EMC_FREQ 0% GR3D_FREQ 99% PLL@41C CPU@45.5C PMIC@100C GPU@41.5C AO@50C thermal@43.25C POM_5V_IN 4429/2856 POM_5V_GPU 1706/359 POM_5V_CPU 528/778
RAM 1098/3963MB (lfb 268x4MB) CPU [14%@102,59%@102,0%@102,3%@102] EMC_FREQ 0% GR3D_FREQ 0% PLL@40.5C CPU@44.5C PMIC@100C GPU@40.5C AO@49C thermal@42.5C POM_5V_IN 1904/2720 POM_5V_GPU 82/319 POM_5V_CPU 165/690
RAM 1098/3963MB (lfb 268x4MB) CPU [13%@102,4%@102,4%@102,1%@102] EMC_FREQ 0% GR3D_FREQ 0% PLL@40C CPU@44.5C PMIC@100C GPU@42C AO@49.5C thermal@43.25C POM_5V_IN 1206/2531 POM_5V_GPU 0/279 POM_5V_CPU 166/625

・・・情報多すぎ。

ドキュメント

https://developer.ridgerun.com/wiki/index.php?title=Xavier/JetPack_4.1/Performance_Tuning/Evaluating_Performance

GR3D_FREQ 99%

って行があるから、GPU使用率 99% に達したという意味かな?

カメラを使用する

note: by default, the Jetson's onboard CSI camera will be used as the video source. If you wish to use a USB webcam instead, change the DEFAULT_CAMERA define at the top of imagenet-camera.cpp to reflect the /dev/video V4L2 device of your USB camera. The model it's tested with is Logitech C920.

ということで、デフォルトでは、オンボードCSIカメラを使用する設定になっている。これは意外。

USBカメラ設定で再コンパイル

USBカメラを使用する場合には、設定ファイルを書き換えて、再コンパイルが必要です。

ここで注意が必要なのは、detectnet-cameraimagenet-camera の2スクリプトそれぞれに、設定ファイルがあるので、両方変えないとだめです。
最初、片方だけ直したせいで、片やWEBカメラ、片やカメラモジュールが起動するという、挙動になり、なぜだろう・・・?と、相当悩みました。

~/jetson-inference/imagenet-camera/imagenet-camera.cpp
~/jetson-inference/detectnet-camera/detectnet-camera.cpp

カメラモジュールについて

Raspberry pi 用の公式カメラモジュールが動きます。

V2.1 を刺したところ正常に認識し、動きました。

V1.4 を刺したところ、認識しませんでした。
ドキュメントには、Version2は動くよーと書いてあるので、V1.4は非対応なのかも。
ただし、手元の v1.4 が壊れていた可能性もあります。