文档章节

Jetson Nano Developer Kit

o
 osc_gu9d45li
发布于 2019/04/09 19:13
字数 1304
阅读 12
收藏 0

精选30+云产品,助力企业轻松上云!>>>

The Jetson Nano Developer Kit is an AI computer for learning and for making. ​ 一个推理框架,用于部署模型到嵌入式设备. ​ Four Steps to Deep Learning

https://github.com/dusty-nv/jetson-inference#system-setup

Hello AI World

环境准备

图像分类

核心类imageNet https://github.com/dusty-nv/jetson-inference/blob/master/imageNet.h imageNet接收image作为input,输出每一种类别的概率. ​ 在编译出来的build/aarch64/bin目录下有2个示例程序

/*
 * 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::ALEXNET to load AlexNet 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;
}
  • 载入图像 loadImageRGBA 加载的图像存储于共享内存,映射到cpu和gpu.实际的内存里的image只有1份,cpu/gpu pointer指向的都是同一份物理内存。

The loaded image will be stored in shared memory that's mapped to both the CPU and GPU. There are two pointers available for access in the CPU and GPU address spaces, but there is really only one copy of the image in memory. Both the CPU and GPU pointers resolve to the same physical memory, without needing to perform memory copies (i.e. cudaMemcpy()). ​

  • 载入神经网络模型 imageNet::Create() GOOGLENET是一个预先训练好的模型,使用的数据集是ImageNet(注意不是imageNet对象).类别有1000个,包括了动植物,常见生活用品等. ​
    // load the GoogleNet image recognition network with TensorRT
    // you can use imageNet::ALEXNET to load AlexNet 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;
    }

  • 对图片进行分类
    Classify返回的是类别对应的index ​
    //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");
    }

These descriptions of the 1000 classes are parsed from ilsvrc12_synset_words.txt when the network gets loaded (this file was previously downloaded when the jetson-inference repo was built). ​ ​

  • 退出 程序退出前要释放掉资源
    // free the network's resources before shutting down
    delete net;
​
    // this is the end of the example!
    return 0;
}

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 and Qt4 are required
find_package(CUDA)
find_package(Qt4)
​
# setup Qt4 for build
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
​
# 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)

没什么要特别说的,主要的依赖如下:

  • find_package(jetson-utils)
  • find_package(jetson-inference)
  • target_link_libraries(my-recognition jetson-inference) ​

实时图片识别

上面的代码展示的是本地图片的识别,这一节给出实时的摄像头拍摄图片识别的demo.

  • iamgenet-camera

o
粉丝 0
博文 500
码字总数 0
作品 0
私信 提问
加载中
请先登录后再评论。
Ubuntu 18.04 LTS安装ROS Melodic版机器人操作系统+Jetson Nano刷机教程-开机配置及Melodic ROS install

PART ONE:https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit guanwang: Included in the Box Your Jetson Nano Developer Kit box includes: Jetson Nano Develo......

Darlingqiang
2019/07/09
0
0
[Jetson Nano]Jetson Nano快速入门

NVIDIA®JetsonNano™开发套件是适用于制造商,学习者和开发人员的小型AI计算机。相比Jetson其他系列的开发板,官方报价只要99美金,可谓是相当有性价比。本文如何是一个快速入门的教程,主要...

osc_mnd6q2ay
2019/03/24
13
0
Jetson Nano系列教程1:烧写系统镜像

下载镜像 NVIDIA官方为Jetson Nano Developer Kit (后面统称为Jetson Nano了)提供了SD卡版本的系统镜像,并且根据JetPack版本不断得在更新。所以你可以直接到NVIDIA 下载中心,下载最新的镜...

osc_pqk6rnzb
2019/12/15
18
0
Amazon Sagemaker 与 NVIDIA Jetson 平台结合打造智能边缘

  随着物联网和AI芯片的发展,未来将会有越来越多的数据在边缘侧处理。很多业务场景已经对边缘智能提出了明确的需求,比如自动驾驶的汽车每天会产生5TB的数据,而智能工厂每天产生的数据高...

osc_ze3jj3wd
06/13
6
0
Amazon Sagemaker 与 NVIDIA Jetson 平台结合打造智能边缘

  随着物联网和AI芯片的发展,未来将会有越来越多的数据在边缘侧处理。很多业务场景已经对边缘智能提出了明确的需求,比如自动驾驶的汽车每天会产生5TB的数据,而智能工厂每天产生的数据高...

机器之心Pro
06/12
0
0

没有更多内容

加载失败,请刷新页面

加载更多

vue input 获取焦点

1、首次加载 autofocus="autofocus" #autofocus 属性规定当页面加载时 input 元素应该自动获得焦点。<input type="text" class="rename_box" v-model="current_edit_text" @input="chang......

横着走的螃蟹
9分钟前
0
0
socket链接(底层)

客户端 #socket.socket表明协议并生成链接实例client #client.connect链接到服务器client #循环输入while true #输入的消息 msg = input #client.send(msg.encode())发送信息只能发送比特流进...

onedotdot
17分钟前
18
0
在线讲解一分快3和值怎么计算的

在线讲解一分快3和值怎么计算的老师:【扣 677~90~572】1.The past is gone and static. Nothing we can do will change it. Thefuture is before us and dynamic. Everything we do will af......

yiren081
17分钟前
16
0
hbase学习

简介 数据存储模型及关系型数据库的区别 一般都是牺牲一致性, 最终达到最终一致性 HBase 概念 区别 基础架构 HBASE 原理和操作 写流程 预写入会写入HLog 里面, 通过HLog 来保证数据不丢失 ...

之渊
18分钟前
15
0
网上彩票为什么会有人带你靠谱吗61861585

老师叩:61861585使用默认的随机源随机排列指定的列表。(打乱list中的数据)sort(List<T> list) 进行排序一个人,身边有多少人,就有多大的世界,有什么样的人,就有什么样的世界。这些人素养...

jiukan49
20分钟前
32
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部