Skip to content

Commit

Permalink
debugging CNN and Max Polling layers (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Jerez committed Oct 28, 2023
1 parent 8a6897e commit 3a5445b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
26 changes: 19 additions & 7 deletions newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,38 +107,47 @@ 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;
}

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;
Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit 3a5445b

Please sign in to comment.