Intel® oneAPI Data Analytics Library
Community support for building compute-intensive applications that run fast on Intel® architecture.

Simple Convolutional Neural Network

Sunwoo_L_
Beginner
184 Views

Hi, 
I am trying to build a simple CNN with DAAL neural network classes and struggling with a pooling layer.

The model only has two layers, conv layer and pooling layer. With my code, there is no error in compile time and it runs well. But the number of dimensions and values are not correct. My input data is 1x1x28x28 float numbers and filter size in conv layer is 1x5x5. So, I checked the result is sized 1x1x24x24. So far, it works finely. But after going through a max-pooling layer, the number of dimensions becomes 14 instead of 12. Also, the values are just zeros. 

Here is the code I wrote. Do you guys have any idea?

 

 float* testData = new float[28*28];
        for (int i=0; i < 1; i++)
                for (int j = 0; j < 28; j++)
                    for (int k = 0; k < 28; k++)
                        testData[i*28*28 + j*28 + k] = float(j) * float(k) + i;

        size_t nDim = 4, dims[] = {1, 1, 28,28};

        SharedPtr<Tensor> bogusData(new HomogenTensor<float>(nDim, dims, (float*)testData));
        convolution2d::forward::Batch<> convolution2dLayerForward;
        maximum_pooling2d::forward::Batch<> pool1(nDim);
        convolution2dLayerForward.input.set(forward::data, bogusData);

        convolution2dLayerForward.parameter->kernelSize = convolution2d::KernelSize(5,5);
        convolution2dLayerForward.parameter->nKernels = 1;

        convolution2dLayerForward.compute();
        // So far, so good.

        SharedPtr<Tensor> conv1_value;
        conv1_value = forwardResult->get(forward::value);
        pool1.input.set(forward::data, conv1_value);
  
        pool1.compute();
        // Values are strange here.

Thank you.

0 Kudos
2 Replies
Daria_K_Intel
Employee
184 Views

Hi,

1x1x14x14 is output size with default values of padding (2,2).
Pooling layer result tensor has dimensions 1x1x12x12 when layer paddings are set to zeros:
pool1.parameter.padding = pooling2d::Padding(0,0); 

Regards,
Daria

Sunwoo_L_
Beginner
184 Views

Thank you, Daria! I see, I will try without the padding. 

Reply