.TH "MPSCNNFullyConnected" 3 "Mon Jul 9 2018" "Version MetalPerformanceShaders-119.3" "MetalPerformanceShaders.framework" \" -*- nroff -*- .ad l .nh .SH NAME MPSCNNFullyConnected .SH SYNOPSIS .br .PP .PP \fC#import \fP .PP Inherits \fBMPSCNNConvolution\fP\&. .SS "Instance Methods" .in +1c .ti -1c .RI "(nonnull instancetype) \- \fBinitWithDevice:weights:\fP" .br .ti -1c .RI "(nonnull instancetype) \- \fBinitWithDevice:convolutionDescriptor:kernelWeights:biasTerms:flags:\fP" .br .ti -1c .RI "(nullable instancetype) \- \fBinitWithCoder:device:\fP" .br .ti -1c .RI "(nonnull instancetype) \- \fBinitWithDevice:\fP" .br .in -1c .SS "Additional Inherited Members" .SH "Detailed Description" .PP This depends on Metal\&.framework The \fBMPSCNNFullyConnected\fP specifies a fully connected convolution layer a\&.k\&.a\&. Inner product layer\&. \fBA\fP fully connected CNN layer is one where every input channel is connected to every output channel\&. The kernel width is equal to width of source image and the kernel height is equal to the height of source image\&. Width and height of the output is 1x1\&. Thus, it takes a srcW x srcH x Ni MPSCNNImage, convolves it with Weights[No][SrcW][srcH][Ni] and produces a 1 x 1 x No output\&. The following must be true: .PP .nf kernelWidth == source\&.width kernelHeight == source\&.height clipRect\&.size\&.width == 1 clipRect\&.size\&.height == 1 .fi .PP One can think of a fully connected layer as a matrix multiplication that flattens an image into a vector of length srcW*srcH*Ni\&. The weights are arragned in a matrix of dimension No x (srcW*srcH*Ni) for product output vectors of length No\&. The strideInPixelsX, strideInPixelsY, and group must be 1\&. Offset is not applicable and is ignored\&. Since clipRect is clamped to the destination image bounds, if the destination is 1x1, one doesn't need to set the clipRect\&. .PP Note that one can implement an inner product using \fBMPSCNNConvolution\fP by setting .PP .nf offset = (kernelWidth/2,kernelHeight/2) clipRect\&.origin = (ox,oy), clipRect\&.size = (1,1) strideX = strideY = group = 1 .fi .PP However, using the \fBMPSCNNFullyConnected\fP for this is better for performance as it lets us choose the most performant method which may not be possible when using a general convolution\&. For example, we may internally use matrix multiplication or special reduction kernels for a specific platform\&. .SH "Method Documentation" .PP .SS "\- (nullable instancetype) \fBinitWithCoder:\fP (NSCoder *__nonnull) aDecoder(nonnull id< MTLDevice >) device" \fBNSSecureCoding\fP 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 initWithCoder:device instead\&. .PP \fBParameters:\fP .RS 4 \fIaDecoder\fP The NSCoder subclass with your serialized \fBMPSKernel\fP .br \fIdevice\fP The MTLDevice on which to make the \fBMPSKernel\fP .RE .PP \fBReturns:\fP .RS 4 \fBA\fP new \fBMPSKernel\fP object, or nil if failure\&. .RE .PP .PP Reimplemented from \fBMPSCNNConvolution\fP\&. .SS "\- (nonnull instancetype) initWithDevice: (nonnull id< MTLDevice >) device" Standard init with default properties per filter type .PP \fBParameters:\fP .RS 4 \fIdevice\fP The device that the filter will be used on\&. May not be NULL\&. .RE .PP \fBReturns:\fP .RS 4 \fBA\fP pointer to the newly initialized object\&. This will fail, returning nil if the device is not supported\&. Devices must be MTLFeatureSet_iOS_GPUFamily2_v1 or later\&. .RE .PP .PP Reimplemented from \fBMPSCNNConvolution\fP\&. .SS "\- (nonnull instancetype) \fBinitWithDevice:\fP (nonnull id< MTLDevice >) device(const \fBMPSCNNConvolutionDescriptor\fP *__nonnull) convolutionDescriptor(const float *__nonnull) kernelWeights(const float *__nullable) biasTerms(\fBMPSCNNConvolutionFlags\fP) flags" Initializes a convolution kernel WARNING: This API is depreated and will be removed in the future\&. It cannot be used when training\&. Also serialization/unserialization wont work for \fBMPSCNNConvolution\fP objects created with this init\&. Please move onto using initWithDevice:weights:\&. .PP \fBParameters:\fP .RS 4 \fIdevice\fP The MTLDevice on which this \fBMPSCNNConvolution\fP filter will be used .br \fIconvolutionDescriptor\fP \fBA\fP pointer to a \fBMPSCNNConvolutionDescriptor\fP\&. .br \fIkernelWeights\fP \fBA\fP pointer to a weights array\&. Each entry is a float value\&. The number of entries is = inputFeatureChannels * outputFeatureChannels * kernelHeight * kernelWidth The layout of filter weight is so that it can be reinterpreted as 4D tensor (array) weight[ outputChannels ][ kernelHeight ][ kernelWidth ][ inputChannels / groups ] Weights are converted to half float (fp16) internally for best performance\&. .br \fIbiasTerms\fP \fBA\fP pointer to bias terms to be applied to the convolution output\&. Each entry is a float value\&. The number of entries is = numberOfOutputFeatureMaps .br \fIflags\fP Currently unused\&. Pass MPSCNNConvolutionFlagsNone .RE .PP \fBReturns:\fP .RS 4 \fBA\fP valid \fBMPSCNNConvolution\fP object or nil, if failure\&. .RE .PP .PP Reimplemented from \fBMPSCNNConvolution\fP\&. .SS "\- (nonnull instancetype) \fBinitWithDevice:\fP (nonnull id< MTLDevice >) device(nonnull id< \fBMPSCNNConvolutionDataSource\fP >) weights" Initializes a fully connected kernel .PP \fBParameters:\fP .RS 4 \fIdevice\fP The MTLDevice on which this \fBMPSCNNFullyConnected\fP filter will be used .br \fIweights\fP \fBA\fP pointer to a object that conforms to the \fBMPSCNNConvolutionDataSource\fP protocol\&. The \fBMPSCNNConvolutionDataSource\fP protocol declares the methods that an instance of \fBMPSCNNFullyConnected\fP uses to obtain the weights and bias terms for the CNN fully connected filter\&. .RE .PP \fBReturns:\fP .RS 4 \fBA\fP valid \fBMPSCNNFullyConnected\fP object or nil, if failure\&. .RE .PP .PP Reimplemented from \fBMPSCNNConvolution\fP\&. .SH "Author" .PP Generated automatically by Doxygen for MetalPerformanceShaders\&.framework from the source code\&.