<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

- (MPSImageDescriptor * __nonnull MPSNNPadding) destinationImageDescriptorForSourceImages: (NSArray< MPSImage * > *__nonnull) sourceImages(NSArray< MPSState * > *__nullable) sourceStates(MPSKernel *__nonnull) kernel(MPSImageDescriptor *__nonnull) inDescriptor [optional]

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:

sourceImages The list of source images to be used
sourceStates The list of source states to be used
kernel The MPSKernel the padding method will be applied to. Set the kernel.offset
inDescriptor MPS will prepare a starting guess based on the padding policy (exclusive of MPSNNPaddingMethodCustom) set for the object. You should adjust the offset and image size accordingly. It is on an autoreleasepool.

Returns:

The MPSImageDescriptor to use to make a MPSImage to capture the results from the filter. The MPSImageDescriptor is assumed to be on an autoreleasepool. Your method must also set the kernel.offset property.

- (instancetype __nullable MPSNNPadding) inverse [optional]

Make a 'inverted' padding policy suitable for a training gradient pass.

- (NSString*__nonnull MPSNNPadding) label [optional]

A human readable string that describes the padding policy. Useful for verbose debugging support.

- (MPSNNPaddingMethod MPSNNPadding) paddingMethod [required]

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