Here is an implementation of img2col
function in Swift:
main.swift1154 chars26 lines
The function takes input as a 4D array, where the first dimension is the batch size, the second dimension is the height of the image, the third dimension is the width of the image, and the fourth dimension is the number of channels. kernelSize
is the size of the kernel, and stride
is the stride of the convolution.
The output of the function is a 2D array, where each row represents one patch. The number of columns is equal to kernelSize * kernelSize * inputChannel
.
gistlibby LogSnag