<MPSNNPadding >(3) | MetalPerformanceShaders.framework | <MPSNNPadding >(3) |
<MPSNNPadding >
#import <MPSNeuralNetworkTypes.h>
Inherits <NSObject>, and <NSSecureCoding>.
(MPSNNPaddingMethod) - paddingMethod
(NSString *__nonnull) - label
(MPSImageDescriptor *__nonnull) -
destinationImageDescriptorForSourceImages:sourceStates:forKernel:suggestedDescriptor:
(instancetype __nullable) - inverse
Determine padding and sizing of result images A MPSNNPaddingMethod must both return a valid MPSImageDescriptor and set the MPSKernel.offset to the correct value. This is a required feature if the MPSNNPaddingMethodCustom bit is set in the paddingMethod.
Some code that may prove helpful:
const int centeringPolicy = 0; // When kernelSize is even: 0 pad bottom right. 1 pad top left. Centers the kernel for even sized kernels. typedef enum Style{
StyleValidOnly = -1,
StyleSame = 0,
StyleFull = 1 }Style; // Typical destination size in one dimension for forward filters (most filters) static int DestSize( int sourceSize, int stride, int filterWindowSize, Style style ){
sourceSize += style * (filterWindowSize - 1); // adjust how many pixels we are allowed to read
return (sourceSize + stride - 1) / stride; // sourceSize / stride, round up } // Typical destination size in one dimension for reverse filters (e.g. convolution transpose) static int DestSizeReverse( int sourceSize, int stride, int filterWindowSize, Style style ){
return (sourceSize-1) * stride + // center tap for the last N-1 results. Take stride into account
1 + // center tap for the first result
style * (filterWindowSize-1); // add or subtract (or ignore) the filter extent } // Find the MPSOffset in one dimension static int Offset( int sourceSize, int stride, int filterWindowSize, Style style ){
// The correction needed to adjust from position of left edge to center per MPSOffset definition
int correction = filterWindowSize / 2;
// exit if all we want is to start consuming pixels at the left edge of the image.
if( 0 )
return correction;
// Center the area consumed in the source image:
// Calculate the size of the destination image
int destSize = DestSize( sourceSize, stride, filterWindowSize, style ); // use DestSizeReverse here instead as appropriate
// calculate extent of pixels we need to read in source to populate the destination
int readSize = (destSize-1) * stride + filterWindowSize;
// calculate number of missing pixels in source
int extraSize = readSize - sourceSize;
// number of missing pixels on left side
int leftExtraPixels = (extraSize + centeringPolicy) / 2;
// account for the fact that the offset is based on the center pixel, not the left edge
return correction - leftExtraPixels; }
Parameters:
Returns:
Make a 'inverted' padding policy suitable for a training gradient pass.
A human readable string that describes the padding policy. Useful for verbose debugging support.
Get the preferred padding method for the node
Generated automatically by Doxygen for MetalPerformanceShaders.framework from the source code.
Mon Jul 9 2018 | Version MetalPerformanceShaders-119.3 |