Page MenuHomec4science

basicnet.cpp
No OneTemporary

File Metadata

Created
Sat, Jun 8, 18:30

basicnet.cpp

#include <eddl/apis/eddl.h>
#include <eddl/apis/eddlT.h>
#include <eddl/tensor/tensor.h>
#include <string>
#include "basicnet.h"
#define NB_CHNS 4
#define L2_K 0.1
#define L2_B 0.1
#define L2_A 0.0
#define DROPOUT_RATE 0.5
BasicNet::BasicNet()
{
using namespace eddl;
layer in_ = Input({1, NB_CHNS, 1280});
layer l = in_;
l = L2(GlorotUniform(Conv(l, 16, {3, 5}, {1,1}, "same")), L2_K);
l = BatchNormalization(l, 0.99, 0.001);
l = Activation(l, "relu");
l = MaxPool(l, {1,2}, {1,2}, "same");
l = L2(GlorotUniform(Conv(l, 32, {3, 3}, {1,1}, "same")), L2_K);
l = BatchNormalization(l, 0.99, 0.001);
l = Activation(l, "relu");
l = MaxPool(l, {1,2}, {1,2}, "same");
l = L2(GlorotUniform(Conv(l, 32, {3, 3}, {2,2}, "same")), L2_K);
l = BatchNormalization(l, 0.99, 0.001);
l = Activation(l, "relu");
l = Dropout(l, DROPOUT_RATE);
l = Flatten(l);
// l = Dense(l, 64, kernel_initialiser='glorot_uniform', bias_initialiser='zeros', kernel_regularizer=L2(l2_k), bias_regularizer=L2(l2_b));
l = L2(GlorotUniform(Dense(l, 64)), L2_K);
l = Activation(l, "relu");
l = Dropout(l, DROPOUT_RATE);
// l = Dense(l, 1, kernel_initialiser='glorot_uniform', bias_initialiser='zeros');
l = GlorotUniform(Dense(l, 2));
l = Activation(l, "softmax");
layer out_ = l;
net = Model({in_}, {out_});
build(net,
sgd(0.01, 0.9, 0.0, true),
{"cross_entropy"},
{"categorical_accuracy"},
CS_CPU(4, "full_mem"));
summary(net);
}
void BasicNet::fit(Tensor* x_train, Tensor* y_train, Tensor* x_val, Tensor* y_val, int batch_size, int epochs, float learning_rate)
{
eddl::setlr(net, {learning_rate});
for(int e=0; e<epochs; e++)
{
eddl::fit(net, {x_train}, {y_train}, batch_size, 1);
eddl::evaluate(net, {x_val}, {y_val});
}
}
void BasicNet::evaluate(Tensor* x, Tensor* y)
{
eddl::evaluate(net, {x}, {y});
}
void BasicNet::save(std::string file_name)
{
eddl::save(net, file_name);
}
void BasicNet::load(std::string file_name)
{
eddl::load(net, file_name);
}

Event Timeline