You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
2.0 KiB

#include "../base/basicProcessingUnit.h"
#include "../layers/avgpoolLayer.h"
#include "../layers/batchnormLayer.h"
#include "../layers/connectedLayer.h"
#include "../layers/convolutionalLayer.h"
#define LOG( X ) m_pLog->Log( "PU", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "PU", this, _LOG_ERROR, X )
#define SLOG( X ) me->m_pLog->Log( "PU-THREAD", NULL, X )
#define SLOG_ERROR( X ) me->m_pLog->Log( "PU-THREAD", NULL, _LOG_ERROR, X )
void cortexProcessingUnit::update_layer(connectedLayer *layer, int batch, float learning_rate, float momentum, float decay){
calcAxpy(layer->m_nOutput, learning_rate / batch, layer->m_pBiasUpdate, 1, layer->m_pBias, 1);
calcScal(layer->m_nOutput, momentum, layer->m_pBiasUpdate, 1);
if (layer->m_bBatchNormalize){
calcAxpy(layer->m_nOutput, learning_rate / batch, layer->m_pScaleUpdate, 1, layer->m_pScale, 1);
calcScal(layer->m_nOutput, momentum, layer->m_pScaleUpdate, 1);
};
calcAxpy(layer->m_nWeight, -decay*batch, layer->m_pWeight, 1, layer->m_pWeightUpdate, 1);
calcAxpy(layer->m_nWeight, learning_rate / batch, layer->m_pWeightUpdate, 1, layer->m_pWeight, 1);
calcScal(layer->m_nWeight, momentum, layer->m_pWeightUpdate, 1);
};
void cortexProcessingUnit::update_layer(convolutionalLayer *layer, int batch, float learning_rate, float momentum, float decay){
int size = layer->m_nSize * layer->m_nSize * layer->m_nIn_Channels * layer->m_nN;
calcAxpy(layer->m_nN, learning_rate / batch, layer->m_pBiasUpdate, 1, layer->m_pBias, 1);
calcScal(layer->m_nN, momentum, layer->m_pBiasUpdate, 1);
if (layer->m_pScale){
calcAxpy(layer->m_nN, learning_rate / batch, layer->m_pScaleUpdate, 1, layer->m_pScale, 1);
calcScal(layer->m_nN, momentum, layer->m_pScaleUpdate, 1);
};
calcAxpy(size, -decay*batch, layer->m_pWeight, 1, layer->m_pWeightUpdate, 1);
calcAxpy(size, learning_rate / batch, layer->m_pWeightUpdate, 1, layer->m_pWeight, 1);
calcScal(size, momentum, layer->m_pWeightUpdate, 1);
};
#undef LOG
#undef LOG_ERROR
#undef SLOG
#undef SLOG_ERROR