From 3a5445bddbdf8bb960eefa76cfebb063e04dc3b6 Mon Sep 17 00:00:00 2001 From: Julio Jerez Date: Fri, 27 Oct 2023 17:08:59 -0700 Subject: [PATCH] debugging CNN and Max Polling layers (wip) --- .../ndSandbox/toolbox/ndTestDeepBrain.cpp | 2 +- .../ndBrainLayerConvolutionalMaxPooling.cpp | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/newton-4.00/applications/ndSandbox/toolbox/ndTestDeepBrain.cpp b/newton-4.00/applications/ndSandbox/toolbox/ndTestDeepBrain.cpp index eca658f29d..4a85e8147a 100644 --- a/newton-4.00/applications/ndSandbox/toolbox/ndTestDeepBrain.cpp +++ b/newton-4.00/applications/ndSandbox/toolbox/ndTestDeepBrain.cpp @@ -538,7 +538,7 @@ static void MnistTrainingSet() layers.PushBack(new ndBrainLayerConvolutionalMaxPooling(conv1->GetOutputWidth(), conv1->GetOutputHeight(), conv1->GetOutputChannels())); const ndBrainLayerConvolutionalMaxPooling* const pooling1 = (ndBrainLayerConvolutionalMaxPooling*)(layers[layers.GetCount() - 1]); - layers.PushBack(new ndBrainLayerConvolutional(pooling1->GetOutputWidth(), pooling1->GetOutputHeight(), pooling1->GetOutputChannels(), 3, 32)); + layers.PushBack(new ndBrainLayerConvolutional(pooling1->GetOutputWidth(), pooling1->GetOutputHeight(), pooling1->GetOutputChannels(), 3, 2)); layers.PushBack(new ndBrainLayerReluActivation(layers[layers.GetCount() - 1]->GetOutputSize())); const ndBrainLayerConvolutional* const conv2 = (ndBrainLayerConvolutional*)(layers[layers.GetCount() - 2]); layers.PushBack(new ndBrainLayerConvolutionalMaxPooling(conv2->GetOutputWidth(), conv2->GetOutputHeight(), conv2->GetOutputChannels())); diff --git a/newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp b/newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp index 8b89ebf912..092a9973f2 100644 --- a/newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp +++ b/newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp @@ -107,30 +107,31 @@ void ndBrainLayerConvolutionalMaxPooling::MakePrediction(const ndBrainVector& in ndAssert(input.GetCount() == GetInputSize()); ndAssert(output.GetCount() == GetOutputSize()); + ndAssert(m_height != 3); ndInt32 baseIn = 0; ndInt32 baseOut = 0; for (ndInt32 k = 0; k < m_channels; ++k) { - for (ndInt32 i = 0; i < (m_height & -1); i += 2) + for (ndInt32 i = 0; i < (m_height & -2); i += 2) { - for (ndInt32 j = 0; j < (m_width & -1); j += 2) + for (ndInt32 j = 0; j < (m_width & -2); j += 2) { ndInt32 index = j; ndBrainFloat maxValue = input[baseIn + j]; if (input[baseIn + j + 1] > maxValue) { index = j + 1; - maxValue = input[baseIn + j + 1]; + maxValue = input[baseIn + index]; } if (input[baseIn + m_width + j] > maxValue) { index = m_width + j; - maxValue = input[baseIn + m_width + j]; + maxValue = input[baseIn + index]; } if (input[baseIn + m_width + j + 1] > maxValue) { index = m_width + j + 1; - maxValue = input[baseIn + m_width + j + 1]; + maxValue = input[baseIn + index]; } output[baseOut + (j >> 1)] = maxValue; m_index[baseOut + (j >> 1)] = baseIn + index; @@ -138,7 +139,15 @@ void ndBrainLayerConvolutionalMaxPooling::MakePrediction(const ndBrainVector& in if (m_width & 1) { - ndAssert(0); + ndInt32 index = m_width - 1; + ndBrainFloat maxValue = input[baseIn + index]; + if (input[baseIn + m_width + index] > maxValue) + { + index = m_width + index; + maxValue = input[baseIn + index]; + } + output[baseOut + (m_width >> 1)] = maxValue; + m_index[baseOut + (m_width >> 1)] = baseIn + index; } baseIn += m_width * 2; @@ -147,7 +156,10 @@ void ndBrainLayerConvolutionalMaxPooling::MakePrediction(const ndBrainVector& in if (m_height & 1) { - ndAssert(0); + //ndInt32 index = m_width - 1; + //ndBrainFloat maxValue = input[baseIn + index]; + //output[output->GetCount()] = maxValue; + //m_index[baseOut + (m_width >> 1)] = baseIn + index; } } }