The following is an implementation of img2col function that works with 2D arrays:
main.swift1243 chars36 linesThe img2col function takes in an input 2D array, kernel size, stride, and padding as input arguments. It pads the input 2D array, and then for each kernel in the input array, it extracts the values from the padded array into an output column vector. Finally, it returns an array of column vectors.
The pad function pads the input array with zeros based on the provided padding argument.
Example usage:
main.swift282 chars9 linesIn the example above, we provide an input array with 3x3 values. The kernelSize is 2x2, and we set stride to 1 and padding to 0. As a result, the output is an array of column vectors with 4x1 dimensions.
gistlibby LogSnag