# the command below is the same as ./simplenn (the default setting)
./simplenn --mode=train --model=lenet5 --pool=max --activ=relu --loss=cross_entropy --init=lecun_uniform
Ex 2) The model above with batch normalization adopted
# the command below is the same as ./simplenn --use_batchnorm=1
./simplenn --mode=train --model=lenet5 --pool=max --activ=relu --loss=cross_entropy --init=lecun_uniform --use_batchnorm=1
Ex 3) model: lenet5, pool: average, hidden layer activation: tanh, loss: mean squared error, weight initialization: xavier uniform
# if pretained weights are not in ./model_zoo, --save_dir should be changed
./simplenn --mode=test --save_dir=./model_zoo --pretrained=lenet5.pth
4. Build custom models
If you want to build your own model, write it in main.cpp file and follow the same process as in 3.1. Since CLI options are not available for custom models, we strongly recommend setting parameters (e.g. batch size, learning rate, decay...) manually before compiling.
Ex 1) Train a simple three-layer DNN model. Note that this model is already defined in SimpleNN and named "linear".
Hello Mr,
Thanks for your code, i can know how operation of CNN and how to train in C++. But I want to use Adam instead of SGD, please help me to create Adam code C++.
This my code:
void Conv2d::update_weight(float lr, float decay, int t)
{
// Update W and b with batch and decay
float beta1 = 0.9f;
float beta2 = 0.999f;
float epsilon = 1e-8;
mkernel = beta1 * mkernel.array() + (1 - beta1) * (dkernel / batch).array();
vkernel = beta2 * vkernel.array() + (1 - beta2) * (dkernel / batch).array().square();
mbias = beta1 * mbias.array() + (1 - beta1) * (dbias / batch).array();
vbias = beta2 * vbias.array() + (1 - beta2) * (dbias / batch).array().square();