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
1.5 KiB
41 lines
1.5 KiB
#include "cpu.h"
|
|
#include "../layers/maxpoolLayer.h"
|
|
|
|
void cpuHOST::forward_layer(maxpoolLayer *layer, cortexSTATE state){
|
|
int w_offset = -1 * layer->m_nPad;
|
|
int h_offset = -1 * layer->m_nPad;
|
|
uint32_t h = layer->m_nOut_Height;
|
|
uint32_t w = layer->m_nOut_Width;
|
|
uint32_t c = layer->m_nIn_Channels;
|
|
for (uint32_t b = 0; b < layer->m_nBatch; ++b){
|
|
for (uint32_t k = 0; k < c; ++k){
|
|
for (uint32_t i = 0; i < h; ++i){
|
|
for (uint32_t j = 0; j < w; ++j){
|
|
int out_index = j + w*(i + h*(k + c*b));
|
|
float max_flt = -FLT_MAX;
|
|
int max_i = -1;
|
|
for (uint32_t n = 0; n < layer->m_nSize; ++n){
|
|
for (uint32_t m = 0; m < layer->m_nSize; ++m){
|
|
uint32_t cur_h = h_offset + i*layer->m_nStride + n;
|
|
uint32_t cur_w = w_offset + j*layer->m_nStride + m;
|
|
uint32_t index = cur_w + layer->m_nIn_Width*(cur_h + layer->m_nIn_Height*(k + b*layer->m_nIn_Channels));
|
|
bool valid = (cur_h >= 0 && cur_h < layer->m_nIn_Height && cur_w >= 0 && cur_w < layer->m_nIn_Width);
|
|
float val = (valid) ? state.input[index] : -FLT_MAX;
|
|
max_i = (val > max_flt) ? index : max_i;
|
|
max_flt = (val > max_flt) ? val : max_flt;
|
|
};
|
|
};
|
|
layer->m_pOutput[out_index] = max_flt;
|
|
layer->m_pIndexes[out_index] = max_i;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
void cpuHOST::backward_layer(maxpoolLayer *layer, cortexSTATE state){
|
|
for (uint32_t i = 0; i < layer->m_nOutputVol; ++i){
|
|
uint32_t index = layer->m_pIndexes[i];
|
|
state.delta[index] += layer->m_pDelta[i];
|
|
};
|
|
};
|