城乡与住房建设部网站首页,网站管理与维护的优势,wordpress怎么加快网站打开速度,开个网站平台要多少钱记得之前#xff0c;使用了bubbling导师复现的python版yolox#xff0c;训练了自建的口罩数据集#xff0c;得到了h5文件#xff0c;又转换成pb文件#xff0c;再使用阿里巴巴的MNN#xff0c;使用它的MNNConvert#xff0c;转换成mnn文件
最终实现了#xff0c;在树莓…记得之前使用了bubbling导师复现的python版yolox训练了自建的口罩数据集得到了h5文件又转换成pb文件再使用阿里巴巴的MNN使用它的MNNConvert转换成mnn文件
最终实现了在树莓派4B上使用mnn推理加速实现了口罩检测判断一个人通过时戴不戴口罩由于需要渲染结果FPS始终维持在20到25左右关闭以后可以在30FPS。 在香橙派OPI4A上烧录官网的Ubuntu镜像使用conda创建虚拟环境安装阿里巴巴的MNN当时用了mnn1.1.3是需要手动编译的只需要修改一些配置得到mnn1.1.3的安装包然后使用pip 安装用yolox的代码运行。最终实现了在相同的输入输出情况下得到了高达40FPS的速度。现在的话直接pip install MNN应该也是可以的
由于目前用户手册没有提及camera1和camera2适配什么摄像头而我的imx219也不能使用电压问题使用了一个垃圾usb摄像头作为输入
8核OPI4A完胜4核树莓派4B 在MNN文档有官方示例重点就是创建interpreter创建session输入输出推理……而这些都前提是你得先转换得到一个mnn模型文件官网也有给出方法一行命令即可工具叫做——MNNConvert
import MNN
import MNN.cv as cv
import MNN.numpy as np
import MNN.expr as expr# 创建interpreter
interpreter MNN.Interpreter(mobilenet_v1.mnn)
# 创建session
config {}
config[precision] low
config[backend] CPU
config[thread] 4
session interpreter.createSession(config)
# 获取会话的输入输出
input_tensor interpreter.getSessionInput(session)
output_tensor interpreter.getSessionOutput(session)# 读取图片
image cv.imread(cat.jpg)dst_height dst_width 224
# 使用ImageProcess处理第一张图片将图片转换为转换为size(224, 224), dtypefloat32并赋值给input_data1
image_processer MNN.CVImageProcess({sourceFormat: MNN.CV_ImageFormat_BGR,destFormat: MNN.CV_ImageFormat_BGR,mean: (103.94, 116.78, 123.68, 0.0),filterType: MNN.CV_Filter_BILINEAL,normal: (0.017, 0.017, 0.017, 0.0)})
image_data image.ptr
src_height, src_width, channel image.shape
input_data1 MNN.Tensor((1, dst_height, dst_width, channel), MNN.Halide_Type_Float, MNN.Tensor_DimensionType_Tensorflow)
#设置图像变换矩阵
matrix MNN.CVMatrix()
x_scale src_width / dst_width
y_scale src_height / dst_height
matrix.setScale(x_scale, y_scale)
image_processer.setMatrix(matrix)
image_processer.convert(image_data, src_width, src_height, 0, input_data1)# 使用cv模块处理第二张图片将图片转换为转换为size(224, 224), dtypefloat32并赋值给input_data2
image cv.imread(TestMe.jpg)
image cv.resize(image, (224, 224), mean[103.94, 116.78, 123.68], norm[0.017, 0.017, 0.017])
input_data2 np.expand_dims(image, 0) # [224, 224, 3] - [1, 224, 224, 3]# 合并2张图片到并赋值给input_data
input_data1 expr.const(input_data1.getHost(), input_data1.getShape(), expr.NHWC) # Tensor - Var
input_data np.concatenate([input_data1, input_data2]) # [2, 224, 224, 3]
input_data MNN.Tensor(input_data) # Var - Tensor# 演示多张图片输入所以将输入resize到[2, 3, 224, 224]
interpreter.resizeTensor(input_tensor, (2, 3, 224, 224))
# 重新计算形状分配内存
interpreter.resizeSession(session)# 拷贝数据到输入Tensor
input_tensor.copyFrom(input_data)# 执行会话推理
interpreter.runSession(session)# 从输出Tensor拷贝出数据
output_data MNN.Tensor(output_tensor.getShape(), MNN.Halide_Type_Float, MNN.Tensor_DimensionType_Caffe)
output_tensor.copyToHostTensor(output_data)# 打印出分类结果: 282为猫385为象
output_var expr.const(output_data.getHost(), [2, 1001])
print(output belong to class: {}.format(np.argmax(output_var, 1)))
# output belong to class: array([282, 385], dtypeint32)