Cody

Problem 44832. Generate Convolution Matrix of 2D Kernel with Different Convolution Shapes (Full, Same, Valid)

Solution 1707450

Submitted on 15 Jan 2019 by Royi Avital
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
CONVOLUTION_SHAPE_FULL = 1; CONVOLUTION_SHAPE_SAME = 2; CONVOLUTION_SHAPE_VALID = 3; maxThr = 1e-9; for numRowsImage = 28:32 for numColsImage = 28:32 mI = rand(numRowsImage, numColsImage); for numRowsKernel = 3:7 for numColsKernel = 3:7 mH = rand(numRowsKernel, numColsKernel); for convShape = 1:3 switch(convShape) case(CONVOLUTION_SHAPE_FULL) numRowsOut = numRowsImage + numRowsKernel - 1; numColsOut = numColsImage + numColsKernel - 1; convShapeString = 'full'; case(CONVOLUTION_SHAPE_SAME) numRowsOut = numRowsImage; numColsOut = numColsImage; convShapeString = 'same'; case(CONVOLUTION_SHAPE_VALID) numRowsOut = numRowsImage - numRowsKernel + 1; numColsOut = numColsImage - numColsKernel + 1; convShapeString = 'valid'; end mORef = conv2(mI, mH, convShapeString); mK = CreateImageConvMtx(mH, numRowsImage, numColsImage, convShape); mO = reshape(mK * mI(:), numRowsOut, numColsOut); disp([' ']); disp(['Validating solution for the following parameters:']); disp(['Image Size - [', num2str(numRowsImage), ' x ', num2str(numColsImage), ']']); disp(['Kernel Size - [', num2str(numRowsKernel), ' x ', num2str(numColsKernel), ']']); disp(['Convolution Shape - ', convShapeString]); mE = mO - mORef; maxAbsDev = max(abs(mE(:))); if(maxAbsDev >= maxThr) disp([' ']); disp(['Validation Failed']); disp([' ']); end assert(maxAbsDev < maxThr); end end end end end

Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 3] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 3] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 3] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 4] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 4] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 4] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 5] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 5] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 5] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 6] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 6] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 6] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 7] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 7] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [3 x 7] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 3] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 3] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 3] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 4] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 4] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 4] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 5] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 5] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 5] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 6] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 6] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 6] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 7] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 7] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [4 x 7] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 3] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 3] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 3] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 4] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 4] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 4] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 5] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 5] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 5] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 6] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 6] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 6] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 7] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 7] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [5 x 7] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 3] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 3] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 3] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 4] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 4] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 4] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 5] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 5] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 5] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 6] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 6] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 6] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 7] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 7] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [6 x 7] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 3] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 3] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 3] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 4] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 4] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 4] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 5] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 5] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 5] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 6] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 6] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 6] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 7] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 7] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 28] Kernel Size - [7 x 7] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 29] Kernel Size - [3 x 3] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 29] Kernel Size - [3 x 3] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 29] Kernel Size - [3 x 3] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 29] Kernel Size - [3 x 4] Convolution Shape - full Validating solution for the following parameters: Image Size - [28 x 29] Kernel Size - [3 x 4] Convolution Shape - same Validating solution for the following parameters: Image Size - [28 x 29] Kernel Size - [3 x 4] Convolution Shape - valid Validating solution for the following parameters: Image Size - [28 x 29] Kernel Size - [3 x...