multi-layer perceptrons, MLP)模型,CvANN_MLP。
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml/ml.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
CvANN_MLP bp; //bp网络
CvANN_MLP_TrainParams params; //bp网络参数
params.train_method = CvANN_MLP_TrainParams::BACKPROP;//使用简单的BP算法,还可使用RPROP
params.bp_dw_scale = 0.1;
params.bp_moment_scale = 0.1;
float labels[4][2] = { { 0,0 },{ 0,0 },{ 1,1 },{ 1,1 } }; //训练标签数据,前两个表示男生,后两个表示女生
Mat labelsMat(4, 2, CV_32FC1, labels);
float trainingData[4][2] = { {186,80},{185,81},{160,50},{161,48} }; //训练数据,两个维度,表示身高和体重
Mat trainingDataMat(4, 2, CV_32FC1, trainingData);
Mat layerSizes = (Mat_<int>(1, 4) << 2, 2, 2, 2);//含有两个隐含层的网络结构,输入、输出层各两个节点,每个隐含层含两个节点
bp.create(layerSizes, CvANN_MLP::SIGMOID_SYM);//激活函数为SIGMOID函数,还可使用高斯函数(CvANN_MLP::GAUSSIAN),阶跃函数(CvANN_MLP::IDENTITY)
bp.train(trainingDataMat, labelsMat, Mat(), Mat(), params);
//bp.save("bp.xml");//存储模型
//bp.load("bp.xml");//读取模型
Mat sampleMat = (Mat_<float>(1, 2) << 184, 79); //测试数据,为一男生
Mat responseMat;
bp.predict(sampleMat, responseMat);
Point maxLoc;
minMaxLoc(responseMat, NULL, NULL, NULL, &maxLoc); //response为1行(1个测试数据),2列(共两种类别),每列表示该数据与该类相似的可能性,这里取最大的一类
if (maxLoc.x == 0)
cout << "Boy" << endl;
if (maxLoc.x == 1)
cout << "Girl" << endl;
return 0;
}
参考:
【模式识别】OpenCV中使用神经网络
opencv中使用bp神经网络
【opencv】神经网络CvANN_MLP分类
multi-layer perceptrons, MLP)模型,CvANN_MLP。的更多相关文章
- 初识spark的MLP模型
初识Spark的MLP模型 1. MLP介绍 Multi-layer Perceptron(MLP),即多层感知器,是一个前馈式的.具有监督的人工神经网络结构.通过多层感知器可包含多个隐藏层,实现对非 ...
- Theano Multi Layer Perceptron 多层感知机
理论 机器学习技法:https://www.coursera.org/course/ntumltwo 假设上述网址不可用的话,自行度娘找别人做好的种子.或者看这篇讲义也能够:http://www.cn ...
- 一目了然卷积神经网络 - An Intuitive Explanation of Convolutional Neural Networks
An Intuitive Explanation of Convolutional Neural Networks 原文地址:https://ujjwalkarn.me/2016/08/11/intu ...
- (转)Introductory guide to Generative Adversarial Networks (GANs) and their promise!
Introductory guide to Generative Adversarial Networks (GANs) and their promise! Introduction Neural ...
- (zhuan) How to Train Neural Networks With Backpropagation
this blog from: http://blog.demofox.org/2017/03/09/how-to-train-neural-networks-with-backpropagation ...
- [转]An Intuitive Explanation of Convolutional Neural Networks
An Intuitive Explanation of Convolutional Neural Networks https://ujjwalkarn.me/2016/08/11/intuitive ...
- An Intuitive Explanation of Convolutional Neural Networks
https://ujjwalkarn.me/2016/08/11/intuitive-explanation-convnets/ An Intuitive Explanation of Convolu ...
- Keras下的文本情感分析简介。与MLP,RNN,LSTM模型下的文本情感测试
# coding: utf-8 # In[1]: import urllib.request import os import tarfile # In[2]: url="http://ai ...
- 【转】OpenCV中使用神经网络 CvANN_MLP
原文见:http://blog.csdn.net/xiaowei_cqu/article/details/9027617 OpenCV的ml模块实现了人工神经网络(Artificial Neural ...
随机推荐
- eclipse安装SVN插件的两种方法
eclipse里安装SVN插件,一般来说,有两种方式: 直接下载SVN插件,将其解压到eclipse的对应目录里 使用eclipse 里Help菜单的“Install New Software”,通过 ...
- Ubuntu flatabulous 主题
在终端输入以下指令 sudo apt-get update sudo apt-get upgrade sudo apt-get install unity-tweak-tool//安装unity tw ...
- python2中新式类和经典类的多重继承调用顺序
class A: def foo(self): print('called A.foo()') class B(A): pass class C(A): def foo(self): print('c ...
- 阿里云服务器win2003下iis整合tomcat共享80端口
阿里云服务器win2003下iis整合tomcat共享80端口 很多机器都用tomcat跟IIS部署不同网站.最近买了阿里云的服务器.于是也想玩一下.网上百度了很多方法.但是都有缺陷说的不是很清楚.通 ...
- vb.net FTP上传下载,目录操作
https://blog.csdn.net/dzweather/article/details/51429107 FtpWebRequest与FtpWebResponse类用来与特定FTP服务器进行沟 ...
- Java项目xml相关配置
一.web.xml //设置会话过期时间,这里单位是分钟 <session-config> <session-timeout>30</session-timeout> ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:接口的基本实现
interface A{ // 定义接口A public static final String AUTHOR = "李兴华" ; // 全局常量 public abstract ...
- CentOS操作系统部署zabbix agent服务
CentOS操作系统部署zabbix agent服务 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看zabbix的官方手册 1>.点击下载 2>.查看Ubunt ...
- MapReduce会自动忽略文件夹下的.开头的文件
MapReduce会自动忽略文件夹下的.开头的文件,跳过这些文件的处理.
- Python 必知的 20 个骚操作!
以下为译文: Python 是一个解释型语言,可读性与易用性让它越来越热门. 正如 Python 之禅中所述: 优美胜于丑陋,明了胜于晦涩. 在你的日常编码中,以下技巧可以给你带来意想不到的收获. ...