Curie神经元算法库——CurieNeurons-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 18080|回复: 29

Curie神经元算法库——CurieNeurons

[复制链接]
发表于 2016-6-15 17:36 | 显示全部楼层 |阅读模式
关于CurieNeurons
CurieNeurons,即Curie神经元,
Neurons能通过示例学习,不用编程,可以通过数据离线学习。
能自主发现新内容或异常。

general-vision提供了两个版本的下载,免费版和专业版,专业版售价19美刀。

免费版下载:
http://pan.baidu.com/s/1jI8kOaa

收费版购买:
http://www.general-vision.com/products/curieneurons/

免费版与收费版区别:

CurieNeurons

CurieNeurons


从字面上理解,就是收费版对动作的识别能更准确。我已经买了收费版,粗略的看了下库,两个版本并没有多大区别,猜测收费版只是添加了传感器数据融合,让数据更为准确。所以暂时不建议大家购买。


下载并通过IDE导入库:
add-lib.jpg


现在我们可以开始我们牛逼哄哄的神经元编程之旅了。

[mw_shl_code=cpp,true]/*
*  ===============================================
  Example sketch using the Intel CurieIMU library and the General Vision CurieNeurons library
  for Intel(R) Curie(TM) devices

  Motion is converted into a simple feature vector as follows:
  [ax'1, ay'1, az'1, gx'1,gy'1, gz'1, ax'2, ay'2, az'2, gx'2, gy'2, gz'2, ...] over a number of time samples
  Note that the values a' and g' are normalized and expand between the running min and max of the a and g signals.

  After calibration is made,
  Use the serial monitor to edit the category of a motion,
    (ex= 1 for vertical, 2 for horizontal, 0 for stillness or anything else),
  Start moving the Curie in an expected direction,
  and when you press Enter the last feature vector is learned.
  
  Note that this "snapshot" approach is simplistic and you may have to teach several times
  a given motion so the neurons store models with different amplitudes, acceleration, etc.
  Ideally we want to learn consecutives vectors for a few seconds.
  
  ===============================================
*/
#include "CurieIMU.h"

int ax, ay, az;         // accelerometer values
int gx, gy, gz;         // gyrometer values

int calibrateOffsets = 1; // int to determine whether calibration takes place or not

#include <CurieNeurons.h>
CurieNeurons hNN;

int catL=0; // category to learn
int prevcat=0; // previously recognized category
int dist, cat, nid, nsr, ncount; // response from the neurons

//
// Variables used for the calculation of the feature vector
//
#define sampleNbr 10  // number of samples to assemble a vector
#define signalNbr  6  // ax,ay,az,gx,gy,gz
int raw_vector[sampleNbr*signalNbr]; // vector accumulating the raw sensor data
byte vector[sampleNbr*signalNbr]; // vector holding the pattern to learn or recognize
int mina=0xFFFF, maxa=0, ming=0xFFFF, maxg=0, da, dg;

void setup()
{
  Serial.begin(9600); // initialize Serial communication
  while (!Serial);    // wait for the serial port to open

  // initialize device
  Serial.println("Initializing IMU device...");
  CurieIMU.begin();

  // use the code below to calibrate accel/gyro offset values
  if (calibrateOffsets == 1)
  {   
    Serial.println("About to calibrate. Make sure your board is stable and upright");
    delay(5000);
    Serial.print("Starting Gyroscope calibration and enabling offset compensation...");
    CurieIMU.autoCalibrateGyroOffset();
    Serial.println(" Done");
    Serial.print("Starting Acceleration calibration and enabling offset compensation...");
    CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0);
    CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0);
    CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1);
    Serial.println(" Done");
  }
  
  // Initialize the neurons and set a conservative Max Influence Field
  hNN.Init();
  hNN.Forget(1000); //set a conservative  Max Influence Field prior to learning
  int value=hNN.MAXIF(); // read the MAXIF back to verify proper SPI communication
  Serial.print("\nMaxif register=");Serial.print(value);
  
  Serial.print("\n\nEntering loop...");
  Serial.print("\nMove the module vertically or horizontally...");
  Serial.print("\ntype 1 + Enter if vertical motion");
  Serial.print("\ntype 2 + Enter if horizontal motion");
  Serial.print("\ntype 0 + Enter for any other motion");
}

void loop()
{   
    // Learn if push button depressed and report if a new neuron is committed
    if (Serial.available() == 2)
    {
      catL = Serial.read();
      char inChar = (char)Serial.read();
      if (inChar == '\n')
      {
        catL = catL - 48;
        Serial.print("\nLearning motion category "); Serial.print(catL);
        // learn 5 consecutive sample vectors
        for (int i=0; i<5; i++)
        {
          getVector(); // the vector array is a global
          //Serial.print("\nVector = ");
          //for (int i=0; i<signalNbr*sampleNbr; i++) {Serial.print(vector);Serial.print("\t");}
          ncount=hNN.Learn(vector, sampleNbr*signalNbr, catL);
        }
        Serial.print("\tNeurons="); Serial.print(ncount);      
      }
    }
    else
    {
      // Recognize
      getVector(); // the vector array is a global
      hNN.Classify(vector, sampleNbr*signalNbr,&dist, &cat, &nid);
      if (cat!=prevcat)
      {
        if (cat!=0x7FFF)
        {
          Serial.print("\nMotion category #"); Serial.print(cat);
        }
        else Serial.print("\nMotion unknown");      
        prevcat=cat;
      }
    }
}  

void getVector()
{
  // the reset of the min and max values is optional depending if you want to
  // use a running min and max from the launch of the script or not
  mina=0xFFFF, maxa=0, ming=0xFFFF, maxg=0, da, dg;
  
  for (int sampleId=0; sampleId<sampleNbr; sampleId++)
  {
    //Build the vector over sampleNbr and broadcast to the neurons
    CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);
   
    // update the running min/max for the a signals
    if (ax>maxa) maxa=ax; else if (ax<mina) mina=ax;
    if (ay>maxa) maxa=ay; else if (ay<mina) mina=ay;
    if (az>maxa) maxa=az; else if (az<mina) mina=az;   
    da= maxa-mina;
   
    // update the running min/max for the g signals
    if (gx>maxg) maxg=gx; else if (gx<ming) ming=gx;
    if (gy>maxg) maxg=gy; else if (gy<ming) ming=gy;
    if (gz>maxg) maxg=gz; else if (gz<ming) ming=gz;   
    dg= maxg-ming;

    // accumulate the sensor data
    raw_vector[sampleId*signalNbr]= ax;
    raw_vector[(sampleId*signalNbr)+1]= ay;
    raw_vector[(sampleId*signalNbr)+2]= az;
    raw_vector[(sampleId*signalNbr)+3]= gx;
    raw_vector[(sampleId*signalNbr)+4]= gy;
    raw_vector[(sampleId*signalNbr)+5]= gz;
  }
  
  // normalize vector
  for(int sampleId=0; sampleId < sampleNbr; sampleId++)
  {
    for(int i=0; i<3; i++)
    {
      vector[sampleId*signalNbr+i]  = (((raw_vector[sampleId*signalNbr+i] - mina) * 255)/da) & 0x00FF;
      vector[sampleId*signalNbr+3+i]  = (((raw_vector[sampleId*signalNbr+3+i] - ming) * 255)/dg) & 0x00FF;
    }
  }
}[/mw_shl_code]




待写


以后我也可以装逼说,我在做深度学习了!









发表于 2016-6-16 18:05 | 显示全部楼层
gewenbin292 发表于 2016-6-16 17:09
http://mp.weixin.qq.com/s?__biz=MzAwNjIzMzczMg==&mid=2650498756&idx=2&sn=240aa7689d8b629382d9546bdd4 ...

事实证明,CurieNeurons也不是一个成熟的东西。。。
创客大爆炸发的教程的例程和现在下载的有区别。。。
现在下载的free中的example,其实是geek版本,但lib并不是,free版直接编译过不了~~~
创客大爆炸那个文章让下载的免费版,但后面例程是收费版里的
而免费版里的例程,调用了收费版的一个函数,直接编译过不了
收费版的,是可以编译过的.......

等Neurons更新了再弄了

点评

其实教程里写了如何调整代码诶~  发表于 2016-7-8 15:00
发表于 2016-6-15 17:38 | 显示全部楼层
听着好高级,首先得有一个神经元101不是
发表于 2016-6-15 17:50 | 显示全部楼层
只能假装看懂了
发表于 2016-6-15 18:18 | 显示全部楼层
明天把IMU的机器学习示例搬过来
发表于 2016-6-15 18:30 | 显示全部楼层

保守估计半年后~
发表于 2016-6-16 17:02 来自手机 | 显示全部楼层
http://mp.weixin.qq.com/s?__biz=MzAwNjIzMzczMg==&mid=2650498756&idx=2&sn=240aa7689d8b629382d9546bdd4e3bca&scene=1&srcid=0614W1xA3QZSPrv5nTXwmPtO&from=groupmessage&isappinstalled=0
发表于 2016-6-16 17:06 来自手机 | 显示全部楼层
以上是创客大爆炸给的教程,我试过了,但感觉识别得不好。是不是没有融化imu数据啊?!最近考试没时间细研究了
发表于 2016-6-16 17:09 来自手机 | 显示全部楼层
http://mp.weixin.qq.com/s?__biz=MzAwNjIzMzczMg==&mid=2650498756&idx=2&sn=240aa7689d8b629382d9546bdd4e3bca&scene=1&srcid=0614W1xA3QZSPrv5nTXwmPtO&from=groupmessage&isappinstalled=0
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 07:44 , Processed in 0.103919 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表