如何使用 Opencv dnn 模块调用 Caffe 预训练模型?
QString modelPrototxt = "D:\\Qt\\qmake\\CaffeModelTest\\caffe\\lenet.prototxt";
QString modelBin = "D:\\Qt\\qmake\\CaffeModelTest\\caffe\\snapshot_iter_10000.caffemodel";
QString imageFile = "D:\\Qt\\qmake\\CaffeModelTest\\caffe\\9.png";
//读取存储在caffe模型文件中的网络模型
cv::dnn::Net net = cv::dnn::readNetFromCaffe(modelPrototxt.toStdString(),modelBin.toStdString());
if (net.empty())
{
qDebug() << "readNetFromCaffe faild";
}
//读取图像文件
cv::Mat img = cv::imread(imageFile.toStdString(),0);
if(img.empty())
{
qDebug() << "imread faild";
}
cv::Mat inputBlob = cv::dnn::blobFromImage(img,0.00390625f, cv::Size(28, 28), cv::Scalar(), false);
cv::Mat prob;
cv::TickMeter t;
for (int i = 0; i < 1; i++)
{
//设置网络的输入层名字(和训练网络模型文件里面的 name 对应)
net.setInput(inputBlob, "data");
t.start();
//设置网络的输出层名字(和训练网络模型文件里面的 name 对应)
prob = net.forward("prob");
t.stop();
}
int classId;
double classProb;
cv::Mat probMat = prob.reshape(1, 1); //reshape the blob to 1x1000 matrix
cv::Point classNumber;
cv::minMaxLoc(probMat, NULL, &classProb, NULL, &classNumber);
classId = classNumber.x;
qDebug() << t.getTimeMicro() << "index:" << classId << "%"<< classProb;
LeNet
name: "LeNet"
input: "data"
input_shape {
dim: 1 # batchsize
dim: 1 # number of channels
dim: 28 # width
dim: 28 # height
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 20
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "pool1"
top: "conv2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 50
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "ip1"
type: "InnerProduct"
bottom: "pool2"
top: "ip1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 500
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
layer {
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 10
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "prob"
type: "Softmax"
bottom: "ip2"
top: "prob"
}
如何使用 Opencv dnn 模块调用 Caffe 预训练模型?的更多相关文章
- 如何使用 opencv 加载 darknet yolo 预训练模型?
如何使用 opencv 加载 darknet yolo 预训练模型? opencv 版本 > 3.4 以上 constexpr const char *image_path = "da ...
- OpenCv dnn模块扩展研究(1)--style transfer
一.opencv的示例模型文件 使用Torch模型[OpenCV对各种模型兼容并包,起到胶水作用], 下载地址: fast_neural_style_eccv16_starry_night.t7 ...
- 手把手教你使用LabVIEW OpenCV DNN实现手写数字识别(含源码)
@ 目录 前言 一.OpenCV DNN模块 1.OpenCV DNN简介 2.LabVIEW中DNN模块函数 二.TensorFlow pb文件的生成和调用 1.TensorFlow2 Keras模 ...
- 手把手教你使用LabVIEW OpenCV dnn实现物体识别(Object Detection)含源码
前言 今天和大家一起分享如何使用LabVIEW调用pb模型实现物体识别,本博客中使用的智能工具包可到主页置顶博客LabVIEW AI视觉工具包(非NI Vision)下载与安装教程中下载 一.物体识别 ...
- 文本分类实战(九)—— ELMO 预训练模型
1 大纲概述 文本分类这个系列将会有十篇左右,包括基于word2vec预训练的文本分类,与及基于最新的预训练模型(ELMo,BERT等)的文本分类.总共有以下系列: word2vec预训练词向量 te ...
- 手把手教你使用LabVIEW OpenCV dnn实现图像分类(含源码)
@ 目录 前言 一.什么是图像分类? 1.图像分类的概念 2.MobileNet简介 二.使用python实现图像分类(py_to_py_ssd_mobilenet.py) 1.获取预训练模型 2.使 ...
- DNN模块开发之利器篇:七种武器
我们在进行DNN模块开发时经常需要调用Dotnetnuke.dll中的方法函数,模块开发用到DNN的方法函数会让你的开发更加得心应手,下面我们就来介绍一下. 1) PortalModuleBase ...
- windows下用c++调用caffe做前向
参考博客: https://blog.csdn.net/muyouhang/article/details/54773265 https://blog.csdn.net/hhh0209/article ...
- 创建新的C++工程来调用Caffe对图片进行识别
前段时间一直在跑Caffe训练数据.之前用训练好的caffemodel对图片进行分类都是用的命令行指令,于是就想着自己新建一个工程来调用caffe,结合classification的代码来对图片进行分 ...
随机推荐
- iOS UIButton文字和图片间距随意调整
代码地址如下:http://www.demodashi.com/demo/11606.html 前记 在开发中,我们经常会遇到这么一种情况,就是一个按钮上面有图片也有文字,但是往往设计并不是我们想要的 ...
- iOS开发-重写description方法,自定义控制台(log)信息
description是所有类都有的一个方法. 我们重写这个方法,可以自定义实例输出的信息. 比如我们创建一个Person类: 在.h文件中添加两个属性: #import <Foundation ...
- mongoDB 高级查询之取模查询$mod
http://hancang2000.i.sohu.com/blog/view/235140698.htm $mod取模运算 查询age取模10等于0的数据 db.student.find( { ...
- 一种在MVC3框架里面设置模板页的方法,不使用_ViewStart
1.新建MasterFilterAttribute类继承ActionFilterAttribute,重写方法OnActionExecuted ,指定ViewResult的MasterName = &q ...
- angular4 radio checkbox 有用
<span *ngFor="let op of [{'id':'a','text':'11'},{'id':'b','text':'2222'},{'id':'cc','text':' ...
- string 的函数
string 有一个很好用到函数:substr(index). 去掉前index个字符.
- Android 四大组件学习之Service六
上几节.我们学习怎样用StartServer启动一个服务,用bindServer去绑定一个服务.以及服务的生命周期,以及什么是IntentService. 也许有读者会发现,我们BindServer中 ...
- 服务器操作系统应该选择Debian/Ubuntu还是CentOS?
任何 Linux 发行版本,在理论上都是一样的.只不过操作有的方便,有的麻烦!yum 是比 apt 弱(这就是企业维护和社区维护的区别,企业自己维护不需要这么多功能)但是任何能在 A 发行版本上实现的 ...
- jxta 2.8x启动了
http://chaupal.github.io/ ———————————————————————————————————————————————————————————————————— 至少两个月 ...
- 对Servlet容器的补充和一个问题的请教
[0]README 0.1)本文是对 一个servlet容器 的补充: 0.2)发这个博文的最终目的是为了请教各位前辈,帮我解决一个问题,问题描述在文末, 谢谢: [1]Servlet容器 1.1) ...