An optimized representation of a graph of neural network image and filter nodes.
- iOS 11.0+
- macOS 10.13+
- tvOS 11.0+
- Metal Performance Shaders
Once you have prepared a graph of
MPSNNFilter, and, if needed,
MPSNNState objects, you may initialize a
MPSNNGraph using the image node that you wish to appear as the result. The graph object will introspect the graph representation and determine which nodes are needed for inputs, and which nodes are produced as output state (if any). Nodes which are not needed to calculate the result image node are ignored. Some nodes may be internally concatenated with other nodes for better performance.
MPSNNGraph construction, the graph attached to the result node will be parsed and reduced to an optimized representation. This representation may be saved using the
NSSecure protocol for later recall.
When decoding a
MPSNNGraph using a
NSCoder, it will be created against the system default
MTLDevice. If you would like to set the device, your
NSCoder should conform to the
In typical usage, some refinement, especially of padding policies, may be required to get the expected answer from Metal Performance Shaders. If the result image is the wrong size, padding is typically the problem. When the answers are incorrect, the
offset or other property may be incorrectly configured at some stage. As the graph is generated starting from an output image node, you may create other graphs starting at any image node within the graph. This will give you a view into the result produced from each intermediate layer with a minimum of fuss. In addition, the usual
debug method is available to inspect objects to make sure they conform to expectation.
Note that certain operations such as neuron filters that follow convolution filters and image concatenation may be optimized away by the
MPSNNGraph when it is constructed. The convolution can do neuron operations as part of its operation. Concatenation is best done by writing the result of earlier filter passes in the right place using
destination rather than by adding an extra copy. Other optimizations may be added as framework capabilities improve.