MXNet (.json, .params)
Background & Context

-
- Underlying format of the MXNet deep learning framework, used by the Wolfram Language.
- Translation is performed automatically between the low-level layers used by MXNet and corresponding high-level layers used by the Wolfram Language.
- The mapping between Wolfram Language layers and MXNet layers is not always invertible.
- Networks saved as MXNet are stored as two separate file: a .json file specifying the network topology and a .params file specifying the numeric arrays used in the network.
Import & Export

- Import["file.json","MXNet"] imports the MXNet network saved as a .json file, loading weights from a corresponding .params file if available.
- The parameter file corresponding to "file.json" is assumed to match the pattern "file*.params" and be located in the same folder.
- Import["file.params","MXNet"] can also be used to directly import network parameters.
- Import["file.json",{"MXNet",elem}] and Import["file.params",{"MXNet",elem}] import the specified element elem from the corresponding file.
- By default, Import["file.json"] is imported as a "JSON" format rather than "MXNet".
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements

-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - Net Import elements, available when importing the .json file:
-
"InputNames" names of the net inputs "LayerAssociation" list of rules for options, properties and settings "Net" import the net as a NetGraph or NetChain "NodeDataset" dataset of MXNet symbol nodes "NodeGraph" graph of nodes of MXNet symbol "NodeGraphPlot" plot of nodes of MXNet symbol "UninitializedNet" import the net without any parameters - Import["file.json","MXNet"] uses the "Net" element by default.
- Parameter Import elements, available when importing the .params file:
-
"ArrayAssociation" import the parameter arrays as an association "ArrayList" import the parameter arrays as a list "ArrayNames" the names of the parameter arrays - Import["file.params","MXNet"] uses the "ArrayAssociation" element by default.
Examples
open allclose allBasic Examples (1)
Define an initialized NetChain:
Import Elements (11)
Net (2)
Import an MXNet net as a NetGraph:
This is equivalent to the following:
If an MXNet net has a parameter file with the same name, it is automatically imported as well:
The "ArrayPath" option can be used to avoid importing the parameter file:
This is equivalent to using the "UninitializedNet" content element:
ArrayAssociation (1)
Import Options (1)
"ArrayPath" (1)
"ArrayPath" allows for an explicit path to a parameter file to be specified:
When it is set to None, no parameters are imported:
Possible Issues (3)
Any NetEncoder or NetDecoder attached to a net is not exported:
The imported net no longer has a NetEncoder:
MXNet model definitions do not preserve information about input and output dimensions. Define a NetChain with the dimensions of "Input" specified:
Export the net to the MXNet format:
The dimensions of the input are no longer known:
The dimensions can be added manually using NetReplacePart:
Recurrent layers that operate on variable-length sequences cannot be exported:

Fixing the sequence length allows for the net to be exported:
Recurrent layers can often not be re-imported:

The reason is that they are not exported to a single MXNet operator, but rather as a computational graph unrolled over the sequence length: