Home | Develop | Download | Contact
example_fcnn_training_smiles.cpp

Programa para el testeo de las funciones Fully Connected Layer.Para compilar o código example_fcnn_training_smiles.cpp:

g++ -static -o example_fcnn_training_smiles example_fcnn_training_smiles.cpp -lpdsramm -lpdsnnmm

Para executar o programa:

./example_fcnn_training_smiles

Retornando por consola:

Ninputs:2
Noutputs:1024
Test[  0]  Accuracy %: 92.8711
Test[  1]  Accuracy %: 93.3984
Test[  2]  Accuracy %: 93.8477
Test[  3]  Accuracy %: 94.3945
Test[  4]  Accuracy %: 94.3945
Test[  5]  Accuracy %: 95.2344
Test[  6]  Accuracy %: 95.1758
...
Test[ 34]  Accuracy %: 100
Test[ 35]  Accuracy %: 100
Test[ 36]  Accuracy %: 100
Test[ 37]  Accuracy %: 100
Test[ 38]  Accuracy %: 100
Test[ 39]  Accuracy %: 100


output in sequence

Código example_fcnn_training_smiles.cpp:

#include <Pds/Ra>
#include <Pds/Nn>
#include <iomanip>
int main(void)
{
unsigned int M=40;
double Acc=0;
// Loading Y data
Pds::Matrix IMGA1=Pds::Matrix::ImportBmpFileAsGray("../manual/imagenes/happy.bmp");
Pds::Matrix IMGA2=Pds::Matrix::ImportBmpFileAsGray("../manual/imagenes/sad.bmp");
Pds::Matrix IMGB1=Pds::Matrix::ImportBmpFileAsGray("../manual/imagenes/self-confidence.bmp");
Pds::Matrix IMGB2=Pds::Matrix::ImportBmpFileAsGray("../manual/imagenes/fear.bmp");
Pds::Matrix IMGC0=Pds::Matrix::ImportBmpFileAsGray("../manual/imagenes/pokerface.bmp");
unsigned int Nlin=IMGA1.Nlin();
unsigned int Ncol=IMGA1.Ncol();
Pds::Matrix Y(5,Nlin*Ncol);
Y.SetRowVector(0,Pds::Vector(IMGA1));
Y.SetRowVector(1,Pds::Vector(IMGA2));
Y.SetRowVector(2,Pds::Vector(IMGB1));
Y.SetRowVector(3,Pds::Vector(IMGB2));
Y.SetRowVector(4,Pds::Vector(IMGC0));
Y=Y.Geq(127);
Pds::Matrix Ys(Y.Size());
// Loading X data
Pds::Matrix X= " 0.0 1.0\n" // happy
" 0.0 -1.0\n" // sad
" 1.0 0.0\n" // self-confidence
"-1.0 0.0\n" // fear
" 0.0 0.0"; // poker face
std::cout<<"Ninputs:"<<X.Ncol()<<std::endl;
std::cout<<"Noutputs:"<<Y.Ncol()<<std::endl;
// training
std::vector<unsigned int> N={X.Ncol(),4096,2048,Y.Ncol()};
Pds::FCNn NN0=Pds::FCNn(N,Pds::Sigmoid,Pds::DSigmoid);
for(unsigned int k=0;(k<M)&&(Acc<1.0);k++)
{
NN0.Training(X,Y,0.1,0.01);
NN0.Predict(X,Ys);
Acc=Pds::Accuracy(Ys.Geq(0.5),Y);
std::cout<<"Test["<<std::setw(3)<<k<<"] ";
std::cout<<"Accuracy %: "<<100.0*Acc<<std::endl;
}
// testing
X=Pds::Matrix(1,X.Ncol()); Ys=Pds::Matrix(1,Y.Ncol());
std::vector<Pds::Matrix> Block;
Pds::Matrix IMG;
for(unsigned int k=0;k<360;k=k+5)
{
X.Set( 0, cos(k*Pds::Ra::Pi/180.0) );
X.Set( 1, sin(k*Pds::Ra::Pi/180.0) );
NN0.Predict(X,Ys);
IMG=Ys.Remodel(Nlin,Ncol)*255;
Block.push_back(IMG);
}
Pds::Matrix::ExportAsGif(Block,"smiles.gif",20);
return 0;
}
La clase tipo Pds::FCNn . Esta clase genera un objeto con dos parametros Nlin y Ncol....
Definition: FCNn.hpp:62
const std::string FCNn
Tag de un objeto de tipo Pds::FCNn.
Definition: NnDefines.hpp:165
bool Training(const Pds::Matrix &X, const Pds::Matrix &Y, double alpha, double lambda)
Treina la NN como um bloque de datos entero X para encontrar una variacion de pesos.
Pds::SampleBlock Predict(const Pds::SampleBlock &In) const
Evalua la capa de la CNN.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed