---
# System prepended metadata

title: NVIDIA Jetson Nano Developer Kit
tags: [nvidia, jetson]

---

# NVIDIA Jetson Nano Developer Kit
## NVIDIA Jetson Nano Developer Kit
![](https://i.imgur.com/8gXIYDT.jpg)

## Getting Started With Jetson Nano Developer Kit(OS Install)
可透過官方提供的 Jetson Nano Developer Kit image 進行作業系統安裝
安裝 Image: [Getting Started With Jetson Nano Developer Kit
](https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write)

**Windows**
1. 下載 [SD Memory Card Formatter for Windows](https://www.sdcard.org/downloads/formatter/eula_windows/) 將 SD 卡格式化
2. 下載 [Etcher](https://www.balena.io/etcher/) 將 image 寫入 SD 卡

**Mac**
* GUI 方式
    下載 [Etcher](https://www.balena.io/etcher/) 將 image 寫入 SD 卡

* Comannd Line 方式
    確認 Mac 的外接硬碟
    ```bash
    $ diskutil list external | fgrep '/dev/disk'
    ```
    刪除 SD 卡上現有磁區，並允許寫入
    ```bash
    $ sudo diskutil partitionDisk /dev/disk<n> 1 GPT "Free Space" "%noformat%" 100%
    ```
    將壓縮的 image 寫入 SD 卡，注意使用 /dev/rdisk 取代 /dev/disk
    ```bash
    $ /usr/bin/unzip -p ~/Downloads/jetson_nano_devkit_sd_card.zip | sudo /bin/dd of=/dev/rdisk<n> bs=1m
    ```
    完成後依照提示取出 SD 卡

**Linux**
* GUI
    下載 [Etcher](https://www.balena.io/etcher/) 將 image 寫入 SD 卡

* Command Line
    確認 SD 位置
    ```bash
    $ dmesg | tail | awk '$3 == "sd" {print}'
    ```
    將壓縮的 image 寫入 SD 卡
    ```bash
    $ /usr/bin/unzip -p ~/Downloads/jetson_nano_devkit_sd_card.zip | sudo /bin/dd of=/dev/sd<x> bs=1M status=progress
    ```
    取出 SD 卡
    ```bash
    $ sudo eject /dev/sd<x>
    ```
完成後開機進行作業系統安裝

**作業系統畫面**
![](https://i.imgur.com/WkZfk1S.jpg)




## Environment Quick Reference
為部署深度學習環境，需預先安裝套件，此步驟為快速部署 command
```bash
$ sudo apt-get update
$ sudo apt-get install git cmake libpython3-dev python3-numpy
$ git clone --recursive https://github.com/dusty-nv/jetson-inference
$ cd jetson-inference
$ mkdir build
$ cd build
$ cmake ../
$ make
$ sudo make install
$ sudo ldconfig
```

### Downloading Models
透過 <font style="color:blue">download-models.sh</font> 挑選需要的訓練網路模組進行安裝，預設包含 GoogleNet, ResNet-18, etc,.
>若已透過上述快速部署 command，當中 cmake 會自動執行此步驟，可跳過此步驟
```bash
$ cd jetson-inference/tools
$ ./download-models.sh
```
![](https://i.imgur.com/arF01zz.png)

### Installing PyTorch
建議使用 python 3 比較沒有問題
>若已透過上述快速部署 command，當中 cmake 會自動執行此步驟，可跳過此步驟
```bash
$ cd jetson-inference/build
$ ./install-pytorch.sh
```
![](https://i.imgur.com/OKUgCbW.png)

### Compiling the Project
透過 make 進行編譯以建立環境
```bash
$ cd jetson-inference/build          # omit if working directory is already build/ from above
$ make
$ sudo make install
$ sudo ldconfig
```

### Directory structure
完成編譯後於 build 底下的路徑結構
lib: library
include: headers
bin: sample binaries
networks: 網路模型
images: 測試圖片

```graphviz
digraph hierarchy{
    nodesep=1.0
    node[color=red, shape=box]
    edge[color=blue]
    build->{aarch64}
    aarch64->{bin include lib}
    bin->{networks images}
}
```

## Classifying Images with ImageNet
透過深度學習網路進行圖像識別，深度學習網路類型多樣，包括識別、偵測與語意分割。透過 imageNet 工具可識別影像，提供了 C++ 與 Python 兩種
* imagenet-console.cpp
* imagenet-console.py

工具路徑
```bash
$ cd jetson-inference/buil/aarch64/bin/
```
使用方法
1. 選擇使用的工具
2. 選擇網路模型
3. 欲識別之圖片之路徑與檔名
4. 輸出圖片之路徑與檔名

```bash
$ 工具 網路模型 欲識別圖片 輸出圖片
```
網路模型為選用選項，可以不選網路模型

C++
```bash
$ ./imagenet-console --network=googlenet images/orange_0.jpg output_0.jpg
```
Python
```bash
$ ./imagenet-console.py --network=googlenet images/orange_0.jpg output_0.jpg
```

### Using The Console Program on Jetson
C++ 影像分類程式
```bash
$ ./imagenet-console --network=googlenet images/orange_0.jpg output_0.jpg
```
Python 影像分類程式
```bash
$ ./imagenet-console.py --network=googlenet images/orange_0.jpg output_0.jpg
```
![](https://i.imgur.com/GQIbQE4.jpg)

使用其他分類模型
C++
```bash=
$ ./imagenet-console --network=resnet-18 images/jellyfish.jpg output_jellyfish.jpg
```
Python
```bash
$ ./imagenet-console.py --network=resnet-18 images/jellyfish.jpg output_jellyfish.jpg
```
![](https://i.imgur.com/lc3FAZi.jpg)

C++
```bash
$ ./imagenet-console --network=resnet-18 images/stingray.jpg output_stingray.jpg
```
Python
```bash
$ ./imagenet-console.py --network=resnet-18 images/stingray.jpg output_stingray.jpg
```
![](https://i.imgur.com/kNkaTya.jpg)

C++
```bash
$ ./imagenet-console.py --network=resnet-18 images/coral.jpg output_coral.jpg
```
Python
```bash
$ ./imagenet-console.py --network=resnet-18 images/coral.jpg output_coral.jpg
```
![](https://i.imgur.com/ll5qdzx.jpg)



### Coding Your Own Image Recognition Program(C++)
**以 C++ 程式語言建立影像識別環境**
```bash
$ mkdir ~/my-recognition
$ cd ~/my-recognition
$ touch my-recognition.cpp
$ touch CMakeLists.txt
$ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/black_bear.jpg 
$ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/brown_bear.jpg
$ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/polar_bear.jpg 
```

使用 C++ 語言撰寫影像識別程式與 cmake 編譯程式

C++ 影像識別程式
```cpp=
/*
 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

// include imageNet header for image recognition
#include <jetson-inference/imageNet.h>

// include loadImage header for loading images
#include <jetson-utils/loadImage.h>


// main entry point
int main(int argc, char** argv){
	// a command line argument containing the image filename is expected,
	// so make sure we have at least 2 args (the first arg is the program)
	if(argc < 2){
		printf("my-recognition:  expected image filename as argument\n");
		printf("example usage:   ./my-recognition my_image.jpg\n");
		return 0;
	}

	// retrieve the image filename from the array of command line args
	const char* imgFilename = argv[1];

	// these variables will be used to store the image data and dimensions
	// the image data will be stored in shared CPU/GPU memory, so there are
	// pointers for the CPU and GPU (both reference the same physical memory)
	float* imgCPU    = NULL;		// CPU pointer to floating-point RGBA image data
	float* imgCUDA   = NULL;		// GPU pointer to floating-point RGBA image data
	int    imgWidth  = 0;		// width of the image (in pixels)
	int    imgHeight = 0;		// height of the image (in pixels)
		
	// load the image from disk as float4 RGBA (32 bits per channel, 128 bits per pixel)
	if(!loadImageRGBA(imgFilename, (float4**)&imgCPU, (float4**)&imgCUDA, &imgWidth, &imgHeight)){
		printf("failed to load image '%s'\n", imgFilename);
		return 0;
	}

	// load the GoogleNet image recognition network with TensorRT
	// you can use imageNet::RESNET_18 to load ResNet-18 model instead
	imageNet* net = imageNet::Create(imageNet::GOOGLENET);

	// check to make sure that the network model loaded properly
	if(!net){
		printf("failed to load image recognition network\n");
		return 0;
	}

	// this variable will store the confidence of the classification (between 0 and 1)
	float confidence = 0.0;

	// classify the image with TensorRT on the GPU (hence we use the CUDA pointer)
	// this will return the index of the object class that the image was recognized as (or -1 on error)
	const int classIndex = net->Classify(imgCUDA, imgWidth, imgHeight, &confidence);

	// make sure a valid classification result was returned	
	if( classIndex >= 0 ){
		// retrieve the name/description of the object class index
		const char* classDescription = net->GetClassDesc(classIndex);

		// print out the classification results
		printf("image is recognized as '%s' (class #%i) with %f%% confidence\n", 
			  classDescription, classIndex, confidence * 100.0f);
	}else{
		// if Classify() returned < 0, an error occurred
		printf("failed to classify image\n");
	}
	
	// free the network's resources before shutting down
	delete net;

	// this is the end of the example!
	return 0;
}
```

CMake 編譯程式
```cmake=
# require CMake 2.8 or greater
cmake_minimum_required(VERSION 2.8)

# declare my-recognition project
project(my-recognition)

# import jetson-inference and jetson-utils packages.
# note that if you didn't do "sudo make install"
# while building jetson-inference, this will error.
find_package(jetson-utils)
find_package(jetson-inference)

# CUDA is required
find_package(CUDA)

# compile the my-recognition program
cuda_add_executable(my-recognition my-recognition.cpp)

# link my-recognition to jetson-inference library
target_link_libraries(my-recognition jetson-inference)
```

建立環境
```bash
$ cd ~/my-recognition
$ cmake.
$ make
```

執行程式
```bash
$ ./my-recognition polar_bear.jpg
image is recognized as 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus' (class #296) with 99.999878% confidence
```


### Coding Your Own Image Recognition Program(Python)
以 Python 程式語言建立影像識別環境
```bash
$ cd ~/
$ mkdir my-recognition-python
$ cd my-recognition-python
$ touch my-recognition.py
$ chmod +x my-recognition.py
$ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/black_bear.jpg 
$ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/brown_bear.jpg
$ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/polar_bear.jpg 
```
使用 Python 程式語言撰寫影像識別程式

Python影像識別程式
```python=
#!/usr/bin/python

import jetson.inference
import jetson.utils

import argparse

# parse the command line
parser = argparse.ArgumentParser()
parser.add_argument("filename", type=str, help="filename of the image to process")
parser.add_argument("--network", type=str, default="googlenet", help="model to use, can be:  googlenet, resnet-18, ect. (see --help for others)")
opt = parser.parse_args()

# load an image (into shared CPU/GPU memory)
img, width, height = jetson.utils.loadImageRGBA(opt.filename)

# load the recognition network
net = jetson.inference.imageNet(opt.network)

# classify the image
class_idx, confidence = net.Classify(img, width, height)

# find the object description
class_desc = net.GetClassDesc(class_idx)

# print out the result
print("image is recognized as '{:s}' (class #{:d}) with {:f}% confidence".format(class_desc, class_idx, confidence * 100))
```

執行程式
```bash
$ ./my-recognition.py polar_bear.jpg
image is recognized as 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus' (class #296) with 99.999878% confidence
```





## Locating Objects with DetectNet
使用 detectnet-console 工具識別，輸入圖片欲識別圖片，輸出識別邊界、座標與信賴區間，預設使用檢測模型為 91-class SSD-Mobilenet2-v2。

C++ 影響檢測程式
```bash
$ ./detectnet-console --network=ssd-mobilenet-v2 images/peds_0.jpg output.jpg
```

Python 影響檢測程式
```bash
$ ./detectnet-console.py --network=ssd-mobilenet-v2 images/peds_0.jpg output.jpg
```
![](https://i.imgur.com/MBoRlCR.jpg)



>


C++ 影響檢測程式
```bash
$ ./detectnet-console images/peds_1.jpg output.jpg
```

Python 影像檢測程式

```bash
$ ./detectnet-console.py images/peds_1.jpg output.jpg
```

![](https://i.imgur.com/VhcQkIE.jpg)

以下為檢測範例，包含各種類型檢測
![](https://i.imgur.com/aHLqIgL.jpg)
![](https://i.imgur.com/ouot0YM.jpg)
![](https://i.imgur.com/un6VSos.jpg)

**可用檢測模型**
| Model | CLI argument | NetworkType enum | Object classes |
| --- | --- | --- | --- | --- |
| SSD-Mobilenet-v1 | ```ssd-mobilenet-v1``` | ```SSD_MOBILENET_V1``` | 91([COCO classes](https://github.com/dusty-nv/jetson-inference/blob/master/data/networks/ssd_coco_labels.txt)) |
| SSD-Mobilenet-v2 | ```ssd-mobilenet-v2``` | ```SSD_MOBILENET_V2``` | 91([COCO classes](https://github.com/dusty-nv/jetson-inference/blob/master/data/networks/ssd_coco_labels.txt)) |
| SSD-Inception-v2 | ```ssd-inception-v2``` | ```SSD_INCEPTION_V2``` | 91([COCO classes](https://github.com/dusty-nv/jetson-inference/blob/master/data/networks/ssd_coco_labels.txt)) |
| DetectNet-COCO-Dog | ```coco-dog``` | ```COCO_DOG``` | dogs |
| DetectNet-COCO-Bottle | ```coco-bottle``` | ```COCO_BOTTLE``` | bottles |
| DetectNet-COCO-Chair | ```coco-chair``` | ```COCO_CHAIR``` | chairs |
| DetectNet-COCO-Airplane | ```coco-airplane``` | ```COCO_AIRPLANE``` | airplanes |
| ped-100 | ```pednet``` | ```PEDNET``` | pedestrians |
| multiped-500 | ```multiped``` | ```PEDNET_MULTI``` | pedestrians, luggage |
| facenet-120 | ```facenet``` | ```FACENET``` | faces |


>如欲下載額外模型，可使用 Model Downloader 工具
```bash
$ cd jetson-inference/tools
./download-models.sh
```





## Semantic Segmentation with SegNet
可透過深度學習進行語義分割(Semantic segmentation)，分類為 pixel 級別，非整張影像。其透過 Full Convolutional Network(FCN) 完成。

下表為可下載之預訓練語義斷詞模型(pre-train semantic segmantation model)
| 資料集(Data set) | 解析度(Resolution) | CLI 參數(CLI Argument) | 準確性(Accuracy) | Jetson Nano | Jetson Xavier |
| --- | --- | --- | --- | --- | --- |
| [CityScapes](https://www.cityscapes-dataset.com) | 512x256 | ```fcn-resnet18-cityscapes-512x256``` | 83.3% | 48 FPS	 | 480 FPS |
| [CityScapes](https://www.cityscapes-dataset.com) | 1024x512 | ```fcn-resnet18-cityscapes-1024x512``` | 87.3% | 12 FPS | 175 FPS |
| [CityScapes](https://www.cityscapes-dataset.com) | 2048x1024 | ```fcn-resnet18-cityscapes-2048x1024``` | 89.6% | 3 FPS | 47 FPS |
| [DeepScene](http://deepscene.cs.uni-freiburg.de) | 576x320 | ```fcn-resnet18-deepscene-576x320``` | 96.4% | 26 FPS | 360 FPS |
| [DeepScene](http://deepscene.cs.uni-freiburg.de) | 864x480 | ```fcn-resnet18-deepscene-864x480``` | 96.9% | 14 FPS | 190 FPS |
| [Multi-Human](https://lv-mhp.github.io) | 512x320 | ```fcn-resnet18-mhp-512x320``` | 86.5% | 34 FPS | 370 FPS |
| [Multi-Human](https://lv-mhp.github.io) | 640x360 | ```fcn-resnet18-mhp-640x360``` | 87.1% | 23 FPS | 325 FPS |
| [Pascal VOC](http://host.robots.ox.ac.uk/pascal/VOC/) | 320x320 | ```fcn-resnet18-voc-320x320``` | 85.9% | 45 FPS | 508 FPS |
| [Pascal VOC](http://host.robots.ox.ac.uk/pascal/VOC/) | 512x320 | ```fcn-resnet18-voc-512x320``` | 88.5% | 34 FPS | 375 FPS |
| [SUN RGB-D](http://rgbd.cs.princeton.edu) | 512x400 | ```fcn-resnet18-sun-512x400``` | 64.3% | 28 FPS | 340 FPS |
| [SUN RGB-D](http://rgbd.cs.princeton.edu) | 640x512 | ```fcn-resnet18-sun-640x512``` | 65.1% | 17 FPS | 224 FPS |

### Segmenting Images from the Command Line

C++ 影像語義分割
```bash
$ ./segnet-console --network=fcn-resnet18-cityscapes images/city_0.jpg output.jpg
```
Python 影像語義分割
```bash
$ ./segnet-console.py --network=fcn-resnet18-cityscapes images/city_0.jpg output.jpg
```
![](https://i.imgur.com/BW7uSlk.jpg)

![](https://i.imgur.com/tAox0Bu.jpg)

![](https://i.imgur.com/q69ctXu.jpg)

:::warning
上述語法無挑選解析度，因此預設皆使用最低解析之網路模組。
:::

Cityscapes 分類與顏色
| Classes | RGB | Colors |
| :---: | :---: | :---: |
| void | 0 0 0  | <font style="color: rgb(0, 0, 0)">void</font> |
| ego_vehicle | 128 64 128 180 | <font style="color: rgb(128, 64, 128)">ego_vehicle</font> |
| ground | 81 0 81 | <font style="color: rgb(81, 0, 81)">ground</font> |
| road | 128 64 128 180 | <font style="color: rgb(128, 64, 128)">road</font> |
| sidewalk | 150 75 200 | <font style="color: rgb(150, 75, 200)">sidewalk</font> |
| building | 70 70 70 | <font style="color: rgb(102, 102, 156)">building</font> |
| wall | 102 102 156 | <font style="color: rgb(190, 153, 153)">wall</font> |
| fence | 190 153 153 | <font style="color: rgb(190, 153, 153)">fence</font> |
| pole | 153 153 153 150 | <font style="color: rgb(153, 153, 153)">pole</font> |
| traffic_light | 250 170 30 | <font style="color: rgb(250, 170, 30)">traffic_light</font> |
| traffic_sign | 250 170 30 | <font style="color: rgb(250, 170, 30)">traffic_sign</font> |
| vegetation | 107 142 35 | <font style="color: rgb(107, 142, 35)">vegetation</font> |
| terrain | 152 251 152 | <font style="color: rgb(152, 251, 152)">terrain</font> |
| sky | 70 130 180 254 | <font style="color: rgb(70, 130, 180)">sky</font> |
| person | 220 20 60 | <font style="color: rgb(220, 20, 60)">person</font> |
| car | 0 0 142 | <font style="color: rgb(0, 0, 142)">car</font> |
| truck | 0 0 70 | <font style="color: rgb(0, 0, 70)">truck</font> |
| bus | 0 60 100 | <font style="color: rgb(0, 60, 100)">bus</font> |
| train | 0 80 100 | <font style="color: rgb(0, 80, 100)">train</font> |
| motorcycle | 0 0 230 | <font style="color: rgb(0, 0, 230)">motorcycle</font> |
| bicycle | 119 11 32 | <font style="color: rgb(119, 11, 32)">bicycle</font> |


### Cityscapes


**不同解析度網路模型**
C++ 影像語義分割 512x256
```bash
$ ./segnet-console --network=fcn-resnet18-cityscapes-512x256 images/city_0.jpg output.jpg
```
![](https://i.imgur.com/NxVybHi.jpg)

C++ 影像語義分割 1024x512
```bash
$ ./segnet-console --network=fcn-resnet18-cityscapes-1024x512 images/city_0.jpg output.jpg
```
![](https://i.imgur.com/KUujOvq.jpg)


C++ 影像語義分割 2048x1024
```bash
$ ./segnet-console --network=fcn-resnet18-cityscapes-2048 images/city_0.jpg output.jpg
```
![](https://i.imgur.com/x3EDdly.jpg)

:::warning
FCN-ResNet18-Cityscapes-2048x1024 為非預設安裝之網路模型，因此需額外使用 ~/jetson-inference/tools/download-models.sh 另外下載。
:::
:::danger
此 script 中第 721 行語法錯誤，雖於執行時顯示為下載解析度 2048x1024 之模組但實際執行為找不到 2048x512 模組，導致下載失敗，須將 512 改為 1024 方可下載成功。
:::


### DeepScene


C++
```bash
$ ./segnet-console --network=fcn-resnet18-deepscene images/trail_0.jpg output_overlay.jpg
$ ./segnet-console --network=fcn-resnet18-deepscene --visualize=mask images/trail_0.jpg output_mask.jpg
```

Python
```bash
$ ./segnet-console.py --network=fcn-resnet18-deepscene images/trail_0.jpg output_overlay.jpg
$ ./segnet-console.py --network=fcn-resnet18-deepscene --visualize=mask images/trail_0.jpg output_mask.jpg
```
![](https://i.imgur.com/FiQR5xO.jpg)

DeepScene 分類與顏色
| Classes | RGB | Colors |
| :---: | :---: | :---: |
| trail | 200 155 75 180 | <font style="color: rgb(200, 155, 75)">trail</font> |
| grass | 85 210 100 | <font style="color: rgb(85, 210, 100)">grass</font> |
| vegetation | 15 100 20 | <font style="color: rgb(15, 100, 20)">vegetation</font> |
| obstacle | 255 185 0 | <font style="color: rgb (255, 185, 0)">obstacle</font> |
| sky | 0 120 255 150 | <font style="color: rgb(0, 120, 255)">sky</font> |


### Multi-Human Parsing (MHP)
C++
```bash
$ ./segnet-console --network=fcn-resnet18-mhp images/humans_0.jpg output.jpg
```
Python
```bash
$ ./segnet-console.py --network=fcn-resnet18-mhp images/humans_0.jpg output.jpg
```

![](https://i.imgur.com/rHc3I5v.jpg)

![](https://i.imgur.com/cuxJ6QW.jpg)


MHP 分類與顏色
| Classes | RGB | Colors |
| --- | --- | --- |
| background | 0 0 0 | <font style="color: rgb(0, 0, 0)">background</font> |
| hat/helmet/headwear | 139 69 19 | <font style="color: rgb(139, 69, 19)">hat/helmet/headwear</font> |
| face | 222 184 135 | <font style="color: rgb(222, 184, 135)">face</font> |
| hair | 210 105 30 | <font style="color: rgb(210, 105, 30)">hair</font> |
| arm | 255 255 0 | <font style="color: rgb(255, 255, 0)">arm</font> |
| hand | 255 165 0 | <font style="color: rgb(255, 165, 0)">hand</font> |
| shirt | 0 255 0 | <font style="color: rgb(0, 255, 0)">shirt</font> |
| jacket/coat | 60 179 113 | <font style="color: rgb(60, 179, 133)">jacket/coat</font> |
| dress/robe | 107 142 35 | <font style="color: rgb(107, 142, 35)">dress/robe</font> |
| bikini/bra | 255 0 0 | <font style="color: rgb(255, 0, 0)">bikini/bra</font> |
| torso_skin | 245 222 179 | <font style="color: rgb(245, 222, 179)">torso_skin</font> |
| pants | 0 0 255 | <font style="color: rgb(0, 0, 255)">pants</font> |
| shorts | 0 255 255 | <font style="color: rgb(0, 255, 255)">shorts</font> |
| socks/stockings | 238 130 238 | <font style="color: rgb(238, 130, 238)">socks/stockings</font> |
| shoe/boot | 128 0 128 | <font style="color: rgb(128, 0, 128)">shoe/boot</font> |
| leg | 255 0 0 | <font style="color: rgb(255, 0, 0)">leg</font> |
| foot | 255 0 255 | <font style="color: rgb(255, 0, 255)">foot</font> |
| backpack/purse/bag | 128 128 128 | <font style="color: rgb(128, 128, 128)">backpack/purse/bag</font> |
| sunglasses/eyewear | 192 192 192 | <font style="color: rgb(192, 192, 192)">sunglasses/eyewear</font> |
| other_accessory | 128 128 128 | <font style="color: rgb(128, 128, 128)">other_accessory</font> |
| other_item | 128 128 128 | <font style="color: rgb(128, 128, 128)">other_item</font> |


### Pascal VOC
C++
```bash
$ ./segnet-console --network=fcn-resnet18-voc images/object_0.jpg output.jpg
```
Python
```bash
$ ./segnet-console.py --network=fcn-resnet18-voc images/object_0.jpg output.jpg
```

![](https://i.imgur.com/lHSFgo9.jpg)

![](https://i.imgur.com/VV0FKah.jpg)

![](https://i.imgur.com/rfUye58.jpg)

VOC 分類與顏色
| Classes | RGB | Colors |
| --- | ---| --- |
| background | 0 0 0 | <font style="color: rgb(0, 0, 0)">background</font> |
| aeroplane | 255 0 0 | <font style="color: rgb(255, 0, 0)">aeroplane</font> |
| bicycle | 0 255 0 | <font style="color: rgb(0, 255, 0)">bicycle</font> |
| bird | 0 255 120 | <font style="color: rgb(0, 255, 120)">bird</font> |
| boat | 0 0 255 | <font style="color: rgb(0, 0, 255)">boat</font> |
| bottle | 255 0 255 | <font style="color: rgb(255, 0, 255)">bottle</font> |
| bus | 70 70 70 220 | <font style="color: rgb(70, 70, 70)">bus</font> |
| car | 102 102 156 | <font style="color: rgb(102, 102, 156)">car</font> |
| cat | 190 153 153 | <font style="color: rgb(190, 153, 153)">cat</font> |
| chair | 180 165 180 | <font style="color: rgb(180, 165, 180)">chair</font> |
| cow | 150 100 100 | <font style="color: rgb(150, 100, 100)">cow</font> |
| diningtable | 153 153 153 150 | <font style="color: rgb(153, 153, 153)">diningtable</font> |
| dog | 250 170 30 | <font style="color: rgb(250, 170, 30)">dog</font> |
| horse | 220 220 0 | <font style="colorf: rgb(220, 220, 0)">horse</font> |
| motorbike | 107 142 35 | <font style="color: rgb(107, 142, 35)">motorbike</font> |
| person | 192 128 128 | <font style="color: rgb(192, 128, 128)">person</font> |
| pottedplant | 70 130 180 254 | <font style="color:rgb (70, 130, 180)">pottedplant</font> |
| sheep | 220 20 60 | <font style="color: rgb(220, 20, 60)">sheep</font> |
| sofa | 0 0 142 | <font style="color: rgb(0, 0, 142)">sofa</font> |
| train | 0 0 70 | <font style="color: rgb(0, 0, 70)">train</font> |
| tvmonitor | 119 11 32 | <font style="color: rgb(119, 11, 32)">tvmonitor</font> |

### SUN RGB-D
C++
```bash
$ ./segnet-console --network=fcn-resnet18-sun images/room_0.jpg output.jpg
```
Python
```bash
$ ./segnet-console.py --network=fcn-resnet18-sun images/room_0.jpg output.jpg
```
![](https://i.imgur.com/wy4LD4Y.jpg)

![](https://i.imgur.com/tV1K7rF.jpg)

![](https://i.imgur.com/rItF3iZ.jpg)

SUN 分類與顏色
| Classes | RGB | Colors|
| --- | --- | --- |
| other | 0 0 0 | <font style="color: rgb(0, 0, 0)">other</font> |
| wall | 128 0 0 | <font style="color: rgb(128, 0, 0)">wall</font> |
| floor | 0 128 0 | <font style="color: rgb(0, 128, 0)">floor</font> |
| cabinet/shelves/bookshelf/dresser | 128 128 0 | <font style="color: rgb(128, 128,0)">cabinet/shelves/bookshelf/dresser</font> |
| bed/pillow | 0 0 128 | <font style="color: rgb(0, 0, 128)">bed/pillow</font> |
| chair | 128 0 128 | <font style="color: rgb(128, 0, 128)">chair</font> |
| sofa | 0 128 128 | <font style="color: rgb(0, 128, 128)">sofa</font> |
| table | 128 128 128 | <font style="color: rgb(128, 128, 128)">table</font> |
| door | 64 0 0 | <font style="color: rgb(64, 0, 0)">door</font> |
| window | 192 0 0 | <font style="color: rgb(192, 0, 0)">window</font> |
| picture/tv/mirror | 192 128 0 | <font style="color: rgb(192, 128, 0)">picture/tv/mirro</font> |
| blinds/curtain | 192 0 128 | <font style="color: rgb(192, 0, 128)">blinds/curtain</font> |
| clothes | 128 64 128 | <font style="color: rgb(128, 64, 128)">clothes</font> |
| ceiling | 0 192 128 | <font style="color: rgb(0, 192, 128)">ceiling</font> |
| books | 128 192 128 | <font style="color: rgb(128, 192, 128)">books</font> |
| fridge | 64 64 0 | <font style="color: rgb(64, 64, 0)">fridge</font> |
| person | 192 192 128 | <font style="color: rgb(192, 192, 128)">person</font> |
| toilet | 128 0 64 | <font style="color: rgb(128, 0, 64)">toilet</font> |
| sink | 0 128 64 | <font style="color: rgb(0, 128, 64)">sink</font> |
| lamp | 128 128 64 | <font style="color: rgb(128,128, 64)">lamp</font> |
| bathtub | 0 0 192 | <font style="color: rgb(0, 0, 192)">bathtub</font> |

### Processing a Directory of Images
這邊提供了 Python 的腳本 ```segnet-batch.py``` 以批次處理整個資料夾的影像
```bash
$ ./segnet-batch.py --network=<網路模型> <影像輸入路徑> <影像輸出路徑>
```

## Transfer Learning with PyTorch
此技術用於重新訓練 DNN 模型，可花費較少的時間。此範例以 Resnet-18 為範例，亦可使用其他網路模型>

### 安裝 PyTorch
```bash
$ cd ~/jetson-inference/build
$ ./install-pytorch.sh
```

### 確認 PyTorch
```bash
$ python
```
或
```bash
$ python3
```
```bash
>>> import torch
>>> print(torch.__version__)
>>> print('CUDA available: ' + str(torch.cuda.is_available()))
>>> a = torch.cuda.FloatTensor(2).zero_()
>>> print('Tensor a = ' + str(a))
>>> b = torch.randn(2).cuda()
>>> print('Tensor b = ' + str(b))
>>> c = a + b
>>> print('Tensor c = ' + str(c))
```
![](https://i.imgur.com/zTTcTdw.png)

```bash
>>> import torchvision
>>> print(torchvision.__version__)
```
其中 torch 版本應為 1.1.0 ， torchvision 版本應為 0.3.0

### Mounting Swap
若使用 Jetson Nano ，則應掛載 4GB 的 swap 空間，training 會大量使用。
執行以下指令建立 swap 檔
```bash
$ sudo fallocate -l 4G /mnt/4GB.swap
$ sudo mkswap /mnt/4GB.swap
$ sudo swapon /mnt/4GB.swap
```

將下列這行加入 /etc/fstab
```
/mnt/4GB.swap    none    swap    sw 0 0
```

### 訓練資料集


## What is Deep Learning?
### 介紹
一般深度學習共分為兩個開發階段：訓練(**training**)與推理(**inference**)。

**Training**
於訓練階段，神經網路會從大量資料集中帶有標記的範例學習，神經網路的權重將優化以識別資料集中的行為模式。深度神經網路擁多層神經元互相連結，更深的網路需花更多時間訓練與評估。
![](https://i.imgur.com/ot9qtX5.jpg)

訓練過程相當耗資源，於傳統運算架構上虛耗費數週或數月，使用GPU可加速該過程至數數天或數小時。

**DIGITS**
DIGITS 為 NVIDIA 開源計畫，可使用 GPU 加速交互訓練網路。
[DIGITS](https://github.com/NVIDIA/DIGITS)

![](https://i.imgur.com/BP24HRp.png)

**Inference**
透過訓練過的權重，神經網路可於運行時即時評估資料，神經網路基於訓練資料學習進行預測與應用稱之為推理，可以有多方應用，包括
* 影像辨識 Image recognition
* 物體檢測 Object detection
* 分割 Segmentation
* 影像定位(單應性估算)Image registration(homography estimation)
* 訊號分析Signal analytics

## DIGITS workflow
透過 NVIDIA 深度學習工具訓練 DNNs 與高效部署






## Reference
[Hello AI World — Meet Jetson Nano](https://youtu.be/9gVupqHqJws)


###### tags: `nvidia` `jetson`