Azure IoT & NVIDIA Jetson 动手实验活动的笔记和感慨(硬核,无图)

前情提要,本人用的是平板,没有图片,并且只讲了下午场。

省流:Azure-onnx模型导出,nano开发者套件-onnx模型推理。

介绍一下我们要用的两个东西

AZURE

Azure 云服务是一个灵活的企业级公有云平台,提供数据库、云服务、云存储、人工智能互联网、CDN等高效、稳定、可扩展的云端服务,Azure 云计算平台还为企业提供一站式解决方案,快速精准定位用户需求,并了解适合企业的各种方案和相关的服务。

如果您是学生或者教师,可以用您的 edu 邮箱申请通过 https://aka.ms/studentgetazure 申请免费的 Azure 资源  

如果您是开发人员或创业者,可以通过 http://azure.com/free 申请免费的 Azure 资源

如果你是大专院校学生,在申请免费azure云出现问题时请发邮件给 kinfeylo@microsoft.com

nvdia的nano开发套件

GPU 128 核 Maxwell

CPU 四核 ARM A57 @ 1.43GHz

内存 4GB 64 位 LPDDR4 25.6 GB/s

存储 microSD 卡(不包含)

视频编码 4K @ 30 | 4x 1080p @ 30 | 9x 720p @ 30 (H.264/H.265)

视频解码 4K @ 60 | 2x 4K @ 30 | 8x 1080p @ 30 | 18x 720p @ 30 (H.264/H.265)

摄像头 2 个 MIPI CSI-2 DPHY 通道

连接 千兆以太网、M.2 Key E

显示 HDMI 和显示端口

USB 4 个 USB 3.0 接口、USB 2.0 Micro-B 接口

其他 GPIO、I2C、I2S、SPI、UART

规格尺寸 69mm x 45mm,260 针边缘接口

官方链接:https://developer.nvidia.com/zh-cn/embedded/jetson-nano-developer-kit

 第一节课程讲了azure的低代码,代码指令在百度网盘:
链接: https://pan.baidu.com/s/1ECDVo-AW9up8w5vPeyscUA?pwd=rz4m 提取码: rz4m  

同时这里是该课程的挑战https://aka.ms/CSCIoT 

应用源码https://github.com/kinfey/EduAICourse,需要通过bingv7进行训练代码:https://www.customvision.ai/,自定义视觉门户,project:Classification:multiclass,General(没有S1),记住要申请bingAPI,创建,口罩图片,train。

以下我代码段,我是平板,没有方法设置

import os
import sys
import onnxruntime
import onnx
import numpy as np
from PIL import Image, ImageDraw
from object_detection import ObjectDetection
import tempfile
import cv2
import matplotlib.pyplot as plt
import onnxruntime
import onnx
import numpy as np
ModelFile ='model.onnx'
ImageFile= 'demo.jpg'
with open('labels_new.txt', 'r') as f:
        labels = [l.strip() for l in f.readlines()]
print(labels)
class ONNXRuntimeObjectDetection(ObjectDetection):
    """Object Detection class for ONNX Runtime"""
    def __init__(self, model_filename, labels):
        super(ONNXRuntimeObjectDetection, self).__init__(labels)
        model = onnx.load(model_filename)
        with tempfile.TemporaryDirectory() as dirpath:
            temp = os.path.join(dirpath, os.path.basename(ModelFile))
            model.graph.input[0].type.tensor_type.shape.dim[-1].dim_param = 'dim1'
            model.graph.input[0].type.tensor_type.shape.dim[-2].dim_param = 'dim2'
            onnx.save(model, temp)
            self.session = onnxruntime.InferenceSession(temp,providers=['TensorrtExecutionProvider'])
        self.input_name = self.session.get_inputs()[0].name
        self.is_fp16 = self.session.get_inputs()[0].type == 'tensor(float16)'
        
    def predict(self, preprocessed_image):
        inputs = np.array(preprocessed_image, dtype=np.float32)[np.newaxis,:,:,(2,1,0)] # RGB -> BGR
        inputs = np.ascontiguousarray(np.rollaxis(inputs, 3, 1))

        if self.is_fp16:
            inputs = inputs.astype(np.float16)

        outputs = self.session.run(None, {self.input_name: inputs})
        return np.squeeze(outputs).transpose((1,2,0)).astype(np.float32)
imcv = cv2.imread(ImageFile)
showImage = plt.imshow(imcv)
od_model = ONNXRuntimeObjectDetection(ModelFile, labels)
image = Image.open(ImageFile)
predictions = od_model.predict_image(image)
print(predictions)
height, width, channels = imcv.shape
print(height)
print(width)
length = len(predictions) 
for i in range(length): 
    left1 = predictions[i]['boundingBox']['left']
    top1 = predictions[i]['boundingBox']['top']
    width1 = predictions[i]['boundingBox']['width']
    height1 = predictions[i]['boundingBox']['height']
    pre = predictions[i]['probability']
    if(pre > 0.5 ):
        left= (int)(left1 * width)
        top = (int)(top1 * height)
        w = (int)(width1 * width + left)
        h = (int)(height1 * height + top)
        cv2.rectangle(imcv,(left,top ),(w,h),(100,0,0),3 )
imgplot = plt.imshow(imcv)
代码段结束

bing上搜索people mask covid关键词,把前50图片打包下载。

看网络,有一些图片下不了,时间较长。

训练ai。维持时间可能较短。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值