MPSCNNBatchNormalization(3) MetalPerformanceShaders.framework MPSCNNBatchNormalization(3)

MPSCNNBatchNormalization

#import <MPSCNNBatchNormalization.h>

Inherits MPSCNNKernel.


(nonnull instancetype) - initWithDevice:dataSource:
(nonnull instancetype) - initWithDevice:dataSource:fusedNeuronDescriptor:
(nonnull instancetype) - initWithDevice:
(nullable instancetype) - initWithCoder:device:
(void) - encodeToCommandBuffer:sourceImage:batchNormalizationState:destinationImage:
(void) - encodeBatchToCommandBuffer:sourceImages:batchNormalizationState:destinationImages:
(void) - encodeToCommandBuffer:sourceImage:destinationState:destinationImage:
(MPSImage *__nonnull) - encodeToCommandBuffer:sourceImage:destinationState:destinationStateIsTemporary:
(void) - encodeBatchToCommandBuffer:sourceImages:destinationStates:destinationImages:
(MPSImageBatch *__nonnull) - encodeBatchToCommandBuffer:sourceImages:destinationStates:destinationStateIsTemporary:
(MPSCNNBatchNormalizationState *__nullable) - resultStateForSourceImage:sourceStates:destinationImage:
(MPSCNNBatchNormalizationState *__nullable) - temporaryResultStateForCommandBuffer:sourceImage:sourceStates:destinationImage:
(void) - reloadDataSource:
(void) - reloadGammaAndBetaFromDataSource
(void) - reloadMeanAndVarianceFromDataSource
(void) - reloadGammaAndBetaWithCommandBuffer:gammaAndBetaState:
(void) - reloadMeanAndVarianceWithCommandBuffer:meanAndVarianceState:


NSUInteger numberOfFeatureChannels
float epsilon
id< MPSCNNBatchNormalizationDataSource > dataSource

This depends on Metal.framework MPSCNNBatchNormalization normalizes input images using per-channel means and variances.

for (c = 0; c < numberOfFeatureChannels; ++c) { input_image = in(:,:,c,:); output_image = (input_image - mean[c]) * gamma[c] / sqrt(variance[c] + epsilon) + beta[c]; out(:,:,c,:) = output_image; }

- (void) encodeBatchToCommandBuffer: (nonnull id< MTLCommandBuffer >) commandBuffer(MPSImageBatch *__nonnull) sourceImages(MPSCNNBatchNormalizationState *__nonnull) batchNormalizationState(MPSImageBatch *__nonnull) destinationImages

Encode this kernel to a command buffer for a batch of images using a batch normalization state.

Parameters:

commandBuffer A valid command buffer to receive the kernel.
sourceImages The batch of source images.
batchNormalizationState A MPSCNNBatchNormalizationState containing weights and/or statistics to use for the batch normalization. If the state is temporary its read count will be decremented.
destinationImages The batch of images to contain the normalized and scaled result images.

- (void) encodeBatchToCommandBuffer: (nonnull id< MTLCommandBuffer >) commandBuffer(MPSImageBatch *__nonnull) sourceImages(MPSStateBatch *__nullable) destinationStates(MPSImageBatch *__nonnull) destinationImages

Encode a MPSCNNKernel with a destination state into a command Buffer. This is typically used during training. The state is commonly a MPSNNGradientState. Please see -resultStateForSourceImages:SourceStates:destinationImage and batch+temporary variants.

Parameters:

commandBuffer A valid MTLCommandBuffer to receive the encoded filter
sourceImages A valid MPSImage object containing the source images.
destinationStates A list of states to be overwritten by results
destinationImages A valid MPSImage to be overwritten by result images. destinationImages may not alias sourceImages, even at different indices.

Reimplemented from MPSCNNKernel.

- (MPSImageBatch * __nonnull) encodeBatchToCommandBuffer: (nonnull id< MTLCommandBuffer >) commandBuffer(MPSImageBatch *__nonnull) sourceImages(__autoreleasing MPSStateBatch *__nullable *__nonnull) outStates(BOOL) isTemporary

Encode a MPSCNNKernel into a command Buffer. Create a MPSImageBatch and MPSStateBatch to hold the results and return them. In the first iteration on this method, encodeToCommandBuffer:sourceImage:destinationImage: some work was left for the developer to do in the form of correctly setting the offset property and sizing the result buffer. With the introduction of the padding policy (see padding property) the filter can do this work itself. If you would like to have some input into what sort of MPSImage (e.g. temporary vs. regular) or what size it is or where it is allocated, you may set the destinationImageAllocator to allocate the image yourself.

This method uses the MPSNNPadding padding property to figure out how to size the result image and to set the offset property. See discussion in MPSNeuralNetworkTypes.h. All images in a batch must have MPSImage.numberOfImages = 1.

Usage:

MPSStateBatch * outStates = nil;    // autoreleased
MPSImageBatch * result = [k encodeBatchToCommandBuffer: cmdBuf

sourceImages: sourceImages
destinationStates: &outStates ];

Parameters:

commandBuffer The command buffer
sourceImages A MPSImages to use as the source images for the filter.
outStates A pointer to storage to hold a MPSStateBatch* where output states are returned

Returns:

An array of MPSImages or MPSTemporaryImages allocated per the destinationImageAllocator containing the output of the graph. The offset property will be adjusted to reflect the offset used during the encode. The returned images will be automatically released when the command buffer completes. If you want to keep them around for longer, retain the images.

Reimplemented from MPSCNNKernel.

- (void) encodeToCommandBuffer: (nonnull id< MTLCommandBuffer >) commandBuffer(MPSImage *__nonnull) sourceImage(MPSCNNBatchNormalizationState *__nonnull) batchNormalizationState(MPSImage *__nonnull) destinationImage

Encode this kernel to a command buffer for a single image using a batch normalization state.

Parameters:

commandBuffer A valid command buffer to receive the kernel.
sourceImage The source MPSImage.
batchNormalizationState A MPSCNNBatchNormalizationState containing weights and/or statistics to use for the batch normalization. If the state is temporary its read count will be decremented.
destinationImage An MPSImage to contain the resulting normalized and scaled image.

- (void) encodeToCommandBuffer: (nonnull id< MTLCommandBuffer >) commandBuffer(MPSImage *__nonnull) sourceImage(MPSState *__nonnull) destinationState(MPSImage *__nonnull) destinationImage

Encode a MPSCNNKernel with a destination state into a command Buffer. This is typically used during training. The state is commonly a MPSNNGradientState. Please see -resultStateForSourceImages:SourceStates: and batch+temporary variants.

Parameters:

commandBuffer A valid MTLCommandBuffer to receive the encoded filter
sourceImage A valid MPSImage object containing the source image.
destinationState A state to be overwritten by additional state information.
destinationImage A valid MPSImage to be overwritten by result image. destinationImage may not alias sourceImage.

Reimplemented from MPSCNNKernel.

- (MPSImage * __nonnull) encodeToCommandBuffer: (nonnull id< MTLCommandBuffer >) commandBuffer(MPSImage *__nonnull) sourceImage(__autoreleasing MPSState *__nullable *__nonnull) outState(BOOL) isTemporary

Encode a MPSCNNKernel into a command Buffer. Create a texture and state to hold the results and return them. In the first iteration on this method, encodeToCommandBuffer:sourceImage:destinationState:destinationImage: some work was left for the developer to do in the form of correctly setting the offset property and sizing the result buffer. With the introduction of the padding policy (see padding property) the filter can do this work itself. If you would like to have some input into what sort of MPSImage (e.g. temporary vs. regular) or what size it is or where it is allocated, you may set the destinationImageAllocator to allocate the image yourself.

This method uses the MPSNNPadding padding property to figure out how to size the result image and to set the offset property. See discussion in MPSNeuralNetworkTypes.h. All images in a batch must have MPSImage.numberOfImages = 1.

Parameters:

commandBuffer The command buffer
sourceImage A MPSImage to use as the source images for the filter.
outState A new state object is returned here.

Returns:

A MPSImage or MPSTemporaryImage allocated per the destinationImageAllocator containing the output of the graph. The offset property will be adjusted to reflect the offset used during the encode. The returned image will be automatically released when the command buffer completes. If you want to keep it around for longer, retain the image. (ARC will do this for you if you use it later.)

Reimplemented from MPSCNNKernel.

- (nullable instancetype) initWithCoder: (NSCoder *__nonnull) aDecoder(nonnull id< MTLDevice >) device

NSSecureCoding compatability While the standard NSSecureCoding/NSCoding method -initWithCoder: should work, since the file can't know which device your data is allocated on, we have to guess and may guess incorrectly. To avoid that problem, use a subclass of NSCoder that implements the <MPSDeviceProvider> protocol to tell MPS the MTLDevice to use.

Parameters:

aDecoder The NSCoder subclass with your serialized MPSKernel
device The MTLDevice on which to make the MPSKernel

Returns:

A new MPSCNNBatchNormalization object, or nil if failure.

Reimplemented from MPSCNNKernel.

- (nonnull instancetype) initWithDevice: (nonnull id< MTLDevice >) device

Use initWithDevice:dataSource instead

Reimplemented from MPSCNNKernel.

- (nonnull instancetype) initWithDevice: (nonnull id< MTLDevice >) device(nonnull id< MPSCNNBatchNormalizationDataSource >) dataSource

Initializes a batch normalization kernel using a data source.

Parameters:

device The MTLDevice on which this filter will be used
dataSource A pointer to a object that conforms to the MPSCNNBatchNormalizationDataSource protocol. The data source provides filter weights and bias terms and, optionally, image statistics which may be used to perform the normalization.

Returns:

A valid MPSCNNBatchNormalization object or nil, if failure.

- (nonnull instancetype) initWithDevice: (nonnull id< MTLDevice >) device(nonnull id< MPSCNNBatchNormalizationDataSource >) dataSource(MPSNNNeuronDescriptor *__nullable) fusedNeuronDescriptor

Initializes a batch normalization kernel using a data source and a neuron descriptor.

Parameters:

device The MTLDevice on which this filter will be used
dataSource A pointer to a object that conforms to the MPSCNNBatchNormalizationDataSource protocol. The data source provides filter weights and bias terms and, optionally, image statistics which may be used to perform the normalization.
fusedNeuronDescriptor A MPSNNNeuronDescriptor object which specifies a neuron activation function to be applied to the result of the batch normalization.

Returns:

A valid MPSCNNBatchNormalization object or nil, if failure.

- (void) reloadDataSource: (__nonnull id< MPSCNNBatchNormalizationDataSource >) dataSource

Reinitialize the filter using a data source.

Parameters:

dataSource The data source which will provide the weights and, optionally, the image batch statistics with which to normalize.

- (void) reloadGammaAndBetaFromDataSource

Reinitialize the filter's gamma and beta values using the data source provided at kernel initialization.

- (void) reloadGammaAndBetaWithCommandBuffer: (__nonnull id< MTLCommandBuffer >) commandBuffer(MPSCNNNormalizationGammaAndBetaState *__nonnull) gammaAndBetaState

Reload data using new gamma and beta terms contained within an MPSCNNNormalizationGammaAndBetaState object.

Parameters:

commandBuffer The command buffer on which to encode the reload.
gammaAndBetaState The state containing the updated weights which are to be reloaded.

- (void) reloadMeanAndVarianceFromDataSource

Reinitialize the filter's mean and variance values using the data source provided at kernel initialization.

- (void) reloadMeanAndVarianceWithCommandBuffer: (__nonnull id< MTLCommandBuffer >) commandBuffer(MPSCNNNormalizationMeanAndVarianceState *__nonnull) meanAndVarianceState

Reload data using new mean and variance terms contained within an MPSCNNNormalizationMeanAndVarianceState object.

Parameters:

commandBuffer The command buffer on which to encode the reload.
meanAndVarianceState The state containing the updated statistics which are to be reloaded.

- (MPSCNNBatchNormalizationState * __nullable) resultStateForSourceImage: (MPSImage *__nonnull) sourceImage(NSArray< MPSState * > *__nullable) sourceStates(MPSImage *__nonnull) destinationImage

Return an MPSCNNBatchNormalizationState object which may be used with a MPSCNNBatchNormalization filter.

Reimplemented from MPSCNNKernel.

- (MPSCNNBatchNormalizationState * __nullable) temporaryResultStateForCommandBuffer: (nonnull id< MTLCommandBuffer >) commandBuffer(MPSImage *__nonnull) sourceImage(NSArray< MPSState * > *__nullable) sourceStates(MPSImage *__nonnull) destinationImage

Return a temporary MPSCNNBatchNormalizationState object which may be used with a MPSCNNBatchNormalization filter.

Reimplemented from MPSCNNKernel.

- (id<MPSCNNBatchNormalizationDataSource>) dataSource [read], [nonatomic], [retain]

The data source the batch normalization was initialized with

- epsilon [read], [write], [nonatomic], [assign]

The epsilon value used in the batch normalization formula to bias the variance when normalizing.

- numberOfFeatureChannels [read], [nonatomic], [assign]

The number of feature channels in an image to be normalized.

Generated automatically by Doxygen for MetalPerformanceShaders.framework from the source code.

Mon Jul 9 2018 Version MetalPerformanceShaders-119.3