Skip to content

Commit

Permalink
more on cnn layer (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Jerez committed Oct 25, 2023
1 parent b22e479 commit eafaca2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
3 changes: 1 addition & 2 deletions newton-4.00/sdk/dBrain/ndBrainLayerConvolutional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,10 @@ void ndBrainLayerConvolutional::MakePrediction(const ndBrainVector& input, ndBra
{
//m_weights.Mul(input, output);
//output.Add(m_bias);
ndAssert(input.GetCount() == GetInputSize());

//output.Set(ndBrainFloat(ndFloat32(0.0f)));
//ndInt32 inputStart = 0;
//ndInt32 outputStart = 0;
ndAssert(0);
output.InitGaussianWeights(0.1f);
//float xxxxx = 0;
// for (ndInt32 i = 0; i < m_numberOfKernels; ++i)
Expand Down
37 changes: 31 additions & 6 deletions newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,28 @@
#include "ndBrainLayerConvolutionalMaxPooling.h"

ndBrainLayerConvolutionalMaxPooling::ndBrainLayerConvolutionalMaxPooling(ndInt32 inputWidth, ndInt32 inputHeight, ndInt32 inputDepth)
:ndBrainLayerActivation(0)
:ndBrainLayerActivation(((inputWidth + 1) / 2) * ((inputHeight + 1) / 2) * inputDepth)
,m_index()
,m_width(inputWidth)
,m_height(inputHeight)
,m_channels(inputDepth)
{
ndAssert(0);
m_index.SetCount(m_neurons);
}

ndBrainLayerConvolutionalMaxPooling::ndBrainLayerConvolutionalMaxPooling(const ndBrainLayerConvolutionalMaxPooling& src)
:ndBrainLayerActivation(src)
,m_index()
,m_width(src.m_width)
,m_height(src.m_height)
,m_channels(src.m_channels)
{
ndAssert(0);
m_index.SetCount(src.m_index.GetCount());
}

ndInt32 ndBrainLayerConvolutionalMaxPooling::GetInputSize() const
{
return m_width * m_height * m_channels;
}

ndBrainLayer* ndBrainLayerConvolutionalMaxPooling::Clone() const
Expand All @@ -47,10 +60,22 @@ const char* ndBrainLayerConvolutionalMaxPooling::GetLabelId() const

void ndBrainLayerConvolutionalMaxPooling::MakePrediction(const ndBrainVector& input, ndBrainVector& output) const
{
ndAssert(0);
ndAssert(input.GetCount() == GetInputSize());
ndAssert(output.GetCount() == GetOutputSize());
//ndAssert(input.GetCount() == output.GetCount());
//for (ndInt32 i = input.GetCount() - 1; i >= 0; --i)
//{
ndInt32 base = 0;
for (ndInt32 k = 0; k < m_channels; ++k)
{
for (ndInt32 i = 0; i < (m_height & -1); i += 2)
{
for (ndInt32 j = 0; j < (m_width & -1); j += 2)
{

}

base += m_width * 2;
}
}
// output[i] = (input[i] > ndBrainFloat(0.0f)) ? input[i] : ndBrainFloat(0.0f);
// ndAssert(ndCheckFloat(output[i]));
//}
Expand Down
7 changes: 7 additions & 0 deletions newton-4.00/sdk/dBrain/ndBrainLayerConvolutionalMaxPooling.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ class ndBrainLayerConvolutionalMaxPooling : public ndBrainLayerActivation
ndBrainLayer* Clone() const;
static ndBrainLayer* Load(const ndBrainLoad* const loadSave);

virtual ndInt32 GetInputSize() const;

const char* GetLabelId() const;
void MakePrediction(const ndBrainVector& input, ndBrainVector& output) const;
void InputDerivative(const ndBrainVector& output, const ndBrainVector& outputDerivative, ndBrainVector& inputDerivative) const;

mutable ndArray<ndInt32> m_index;
ndInt32 m_width;
ndInt32 m_height;
ndInt32 m_channels;
};

#endif
Expand Down

0 comments on commit eafaca2

Please sign in to comment.