#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。的更多相关文章

  1. 初识spark的MLP模型

    初识Spark的MLP模型 1. MLP介绍 Multi-layer Perceptron(MLP),即多层感知器,是一个前馈式的.具有监督的人工神经网络结构.通过多层感知器可包含多个隐藏层,实现对非 ...

  2. Theano Multi Layer Perceptron 多层感知机

    理论 机器学习技法:https://www.coursera.org/course/ntumltwo 假设上述网址不可用的话,自行度娘找别人做好的种子.或者看这篇讲义也能够:http://www.cn ...

  3. 一目了然卷积神经网络 - An Intuitive Explanation of Convolutional Neural Networks

    An Intuitive Explanation of Convolutional Neural Networks 原文地址:https://ujjwalkarn.me/2016/08/11/intu ...

  4. (转)Introductory guide to Generative Adversarial Networks (GANs) and their promise!

    Introductory guide to Generative Adversarial Networks (GANs) and their promise! Introduction Neural ...

  5. (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 ...

  6. [转]An Intuitive Explanation of Convolutional Neural Networks

    An Intuitive Explanation of Convolutional Neural Networks https://ujjwalkarn.me/2016/08/11/intuitive ...

  7. An Intuitive Explanation of Convolutional Neural Networks

    https://ujjwalkarn.me/2016/08/11/intuitive-explanation-convnets/ An Intuitive Explanation of Convolu ...

  8. Keras下的文本情感分析简介。与MLP,RNN,LSTM模型下的文本情感测试

    # coding: utf-8 # In[1]: import urllib.request import os import tarfile # In[2]: url="http://ai ...

  9. 【转】OpenCV中使用神经网络 CvANN_MLP

    原文见:http://blog.csdn.net/xiaowei_cqu/article/details/9027617 OpenCV的ml模块实现了人工神经网络(Artificial Neural ...

随机推荐

  1. [CISCN2019 华北赛区 Day1 Web2]ikun

    知识点:逻辑漏洞.jwt密钥破解.python反序列化漏洞 进入靶机查看源码: 提示需要买到lv6,注册账号发现给了1000块钱,根据ctf套路应该是用很低的价格买很贵的lv6,首页翻了几页都没发现l ...

  2. 1-4SpringBoot操作之Spring-Data-Jpa(一)

    Spring-Data-Jpa JPA(Java Persistence API)定义了一系列对象持久化的标准, 目前实现这一规范的产品有Hibernate.TopLink等. Spring Data ...

  3. SciPy 教程

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...

  4. java 根据传入的时间获取当前月的第一天的0点0分0秒和最后一天的23点59分59秒

    /** * 获取指定日期所在月份开始的时间 * lkeji * @return */ public static String getMonthBegin(String specifiedDay) { ...

  5. pta 拯救007(Floyd)

    7-9 拯救007(25 分) 在老电影“007之生死关头”(Live and Let Die)中有一个情节,007被毒贩抓到一个鳄鱼池中心的小岛上,他用了一种极为大胆的方法逃脱 —— 直接踩着池子里 ...

  6. 【题集】k倍区间(抽屉原理)

    例1:http://lx.lanqiao.cn/problem.page?gpid=T444 蓝桥杯 问题描述 给定一个长度为N的数列,A1, A2, ... AN,如果其中一段连续的子序列Ai, A ...

  7. HIWORD HIBYTE

    #include "pch.h" #include <iostream> #include<Windows.h> int main() { ; WORD i ...

  8. ubuntu16下安装mongodb 3.6

    1.安装MongoDB社区版     # 1. 导入MongoDB public GPG Key sudo apt-key adv --keyserver hkp://keyserver.ubuntu ...

  9. 关于 vue.config.js 文件的配置

    相关文档: https://cli.vuejs.org/zh/config/#vue-config-js

  10. Typescript 实战 --- (9)ES6与CommonJS的模块系统

    1.ES6模块系统 1-1.export 导出 (1).单独导出 // a.ts export let a = 1; (2).批量导出 // a.ts let b = 2; let c = 3; ex ...