diff --git a/newton-4.00/applications/ndSandbox/toolbox/ndTestDeepBrain.cpp b/newton-4.00/applications/ndSandbox/toolbox/ndTestDeepBrain.cpp index 4a85e8147a..6f893c50ce 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, 2)); + layers.PushBack(new ndBrainLayerConvolutional(pooling1->GetOutputWidth(), pooling1->GetOutputHeight(), pooling1->GetOutputChannels(), 3, 3)); 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())); @@ -613,7 +613,7 @@ void ndTestDeedBrian() // //xxx.PushBack(ndGaussianRandom(0.0f, 0.1f)); // xxx.PushBack(1.0f); //} - //xxx.GaussianNormalize(); + //xxx.GaussianNormalize();/ //ThreeLayersTwoInputsTwoOutputs(); //MnistTrainingSet(); diff --git a/newton-4.00/sdk/dBrain/ndBrainLayerConvolutional.cpp b/newton-4.00/sdk/dBrain/ndBrainLayerConvolutional.cpp index 7254b974d8..d591c5007b 100644 --- a/newton-4.00/sdk/dBrain/ndBrainLayerConvolutional.cpp +++ b/newton-4.00/sdk/dBrain/ndBrainLayerConvolutional.cpp @@ -68,7 +68,6 @@ ndBrainLayerConvolutional::ndBrainLayerConvolutional(const ndBrainLayerConvoluti ,m_numberOfKernels(src.m_numberOfKernels) ,m_outputWidth(src.m_outputWidth) ,m_outputHeight(src.m_outputHeight) - { } diff --git a/newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp b/newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp index 092a9973f2..05acdf4981 100644 --- a/newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp +++ b/newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp @@ -107,59 +107,80 @@ 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) { + const ndInt32 base = k * m_height * m_width; + const ndBrainMemVector in(&input[base], m_height * m_width); + + ndInt32 baseIn = 0; for (ndInt32 i = 0; i < (m_height & -2); i += 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) + ndInt32 index = baseIn + j; + ndBrainFloat maxValue = in[index]; + if (in[baseIn + j + 1] > maxValue) { - index = j + 1; - maxValue = input[baseIn + index]; + index = baseIn + j + 1; + maxValue = in[index]; } - if (input[baseIn + m_width + j] > maxValue) + if (in[baseIn + m_width + j] > maxValue) { - index = m_width + j; - maxValue = input[baseIn + index]; + index = baseIn + m_width + j; + maxValue = in[index]; } - if (input[baseIn + m_width + j + 1] > maxValue) + if (in[baseIn + m_width + j + 1] > maxValue) { - index = m_width + j + 1; - maxValue = input[baseIn + index]; + index = baseIn + m_width + j + 1; + maxValue = in[index]; } output[baseOut + (j >> 1)] = maxValue; - m_index[baseOut + (j >> 1)] = baseIn + index; + m_index[baseOut + (j >> 1)] = base + index; } if (m_width & 1) { - ndInt32 index = m_width - 1; - ndBrainFloat maxValue = input[baseIn + index]; - if (input[baseIn + m_width + index] > maxValue) + ndInt32 index = baseIn + m_width - 1; + ndBrainFloat maxValue = in[index]; + if (in[baseIn + m_width + m_width - 1] > maxValue) { - index = m_width + index; - maxValue = input[baseIn + index]; + index = baseIn + m_width + m_width - 1; + maxValue = in[index]; } output[baseOut + (m_width >> 1)] = maxValue; - m_index[baseOut + (m_width >> 1)] = baseIn + index; + m_index[baseOut + (m_width >> 1)] = base + index; } baseIn += m_width * 2; - baseOut += m_width >> 1; + baseOut += (m_width + 1) >> 1; } if (m_height & 1) { - //ndInt32 index = m_width - 1; - //ndBrainFloat maxValue = input[baseIn + index]; - //output[output->GetCount()] = maxValue; - //m_index[baseOut + (m_width >> 1)] = baseIn + index; + for (ndInt32 j = 0; j < (m_width & -2); j += 2) + { + ndInt32 index = baseIn + j; + ndBrainFloat maxValue = in[index]; + if (in[baseIn + j + 1] > maxValue) + { + index = baseIn + j + 1; + maxValue = in[index]; + } + output[baseOut + (j >> 1)] = maxValue; + m_index[baseOut + (j >> 1)] = base + index; + } + + if (m_width & 1) + { + ndInt32 index = baseIn + m_width - 1; + ndBrainFloat maxValue = in[index]; + output[baseOut + (m_width >> 1)] = maxValue; + m_index[baseOut + (m_width >> 1)] = base + index; + } + + baseIn += m_width * 2; + baseOut += (m_width + 1) >> 1; } } }