如何使用 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的代码来对图片进行分 ...
随机推荐
- HTML5事件-pageshow 和 pagehide
<!doctype html> <html> <head> <title>html5事件</title> <meta charset= ...
- tcp/ip ---数据链路层
- git服务器gitlab之搭建和使用
git服务器比较有名的是gitosis和gitolite,这两个管理和使用起来稍微有些复杂,没有web页面,而gitlab则是类似于github的一个工具,github无法免费建立私有仓库,并且为了代 ...
- android动画具体解释二 属性动画原理
property动画是一个强大的框架,它差点儿能使你动画不论什么东西. 你能够定义一个动画来改变对象的不论什么属性,不论其是否被绘制于屏幕之上. 一个属性动画在一定时间内多次改变一个属性(对象的一个字 ...
- 使用apxs安装apache模块
使用apxs安装apache模块 ---by石锅拌饭 1.缘由 前几天迁移系统.发现配置了fastcgi的一个脚本下载文件总是提示类似Connection reset ...
- Spring Boot全日志设置
说在前面 这里日志分两种.一种是tomcat的输出(系统)日志,一种是自己定义的日志. 系统日志设置 目标 当springboot接收到请求时记录日志到文件中 实现 你只需要在你的绿叶applicat ...
- Vue 组件6内联模板
如果子组件有inline-template特性,组件将把它的内容当做模板,而不是把它当做分发内容,这样模板更灵活. <my-component inline-template> <d ...
- MFC invalidate和RedrawWindow区别
Invalidate()函数是强制系统进行重画,但是不一定就马上进行重画.因为Invalidate()只是通知系统,此时的窗口已经变为无效.强制系统调用WM_PAINT,而这个消息只是Post就是将该 ...
- Tree UVA - 548 已知中序遍历和后序遍历,求这颗二叉树。
You are to determine the value of the leaf node in a given binary tree that is the terminal node of ...
- UVa 12563 劲歌金曲 刘汝佳第二版例题9-5;
Problem J Jin Ge Jin Qu [h]ao (If you smiled when you see the title, this problem is for you ^_^) Fo ...