FileFormats module
ControllerFormats.FileFormats
— ModuleFileFormats
Module to parse and write file formats of controllers.
Reading neural networks
ControllerFormats.FileFormats.read_MAT
— Functionread_MAT(filename::String; act_key::String)
Read a neural network stored in MATLAB's MAT
format. This function requires to load the MAT.jl
library.
Input
filename
– name of theMAT
fileact_key
– key used for the activation functionsnet_key
– (optional; default:nothing
) key used for the neural network
Output
Notes
The MATLAB
file encodes a dictionary. If net_key
is given, then the dictionary contains another dictionary under this key. Otherwise the outer dictionary directly contains the following:
- A vector of weight matrices (under the name
"W"
) - A vector of bias vectors (under the name
"b"
) - A vector of strings for the activation functions (under the name passed via
act_key
)
ControllerFormats.FileFormats.read_NNet
— Functionread_NNet(filename::String)
Read a neural network stored in NNet
format.
Input
filename
– name of theNNet
file
Output
Notes
The format assumes that all layers but the output layer use ReLU activation (the output layer uses the identity activation).
The format looks like this (each line may optionally be terminated by a comma):
- Header text, each line beginning with "//"
- Comma-separated line with four values: number of layer operations, number of inputs, number of outputs, maximum layer size
- Comma-separated line with the layer sizes
- Flag that is no longer used
- Minimum values of inputs
- Maximum values of inputs
- Mean values of inputs and one value for all outputs
- Range values of inputs and one value for all outputs
- Blocks of lines describing the weight matrix and bias vector for a layer; each matrix row is written as a comma-separated line, and each vector entry is written in its own line
The code follows this implementation.
ControllerFormats.FileFormats.read_ONNX
— Functionread_ONNX(filename::String; [input_dimension=nothing])
Read a neural network stored in ONNX format. This function requires to load the ONNX.jl
library.
Input
filename
– name of theONNX
fileinput_dimension
– (optional; default:nothing
) input dimension (required byONNX.jl
parser); see the notes below
Output
Notes
This implementation assumes the following structure:
- First comes the input vector (which is ignored).
- Next come the weight matrices
W
(transposed) and bias vectorsb
in pairs in the order in which they are applied. - Next come the affine maps and the activation functions in the order in which they are applied. The last layer does not have an activation function.
Some of these assumptions are currently not validated. Hence it may happen that this function returns a result that is incorrect.
If the argument input_dimension
is not provided, the file is parsed an additional time to read the correct number (which is inefficient).
ControllerFormats.FileFormats.read_POLAR
— Functionread_POLAR(filename::String)
Read a neural network stored in POLAR format.
Input
filename
– name of the POLAR file
Output
Notes
The POLAR format uses the same parameter format as Sherlock (see read_Sherlock
) but allows for general activation functions.
In addition, the last two lines are:
0.0
1.0
The reference parser and writer can be found here.
ControllerFormats.FileFormats.read_Sherlock
— Functionread_Sherlock(filename::String)
Read a neural network stored in Sherlock format.
Input
filename
– name of the Sherlock file
Output
Notes
All layers including the output layer implicitly use a ReLU activation function.
ControllerFormats.FileFormats.read_YAML
— Functionread_YAML(filename::String)
Read a neural network stored in YAML format. This function requires to load the YAML.jl
library.
Input
filename
– name of theYAML
file
Output
Writing neural networks
ControllerFormats.FileFormats.write_NNet
— Functionwrite_NNet(N::FeedforwardNetwork, filename::String)
Write a neural network to a file in NNet
format.
Input
N
– feedforward neural networkfilename
– name of the output file
Output
nothing
. The network is written to the output file.
Notes
The NNet format assumes that all layers but the output layer use ReLU activation (the output layer uses the identity activation).
Some non-important part of the output (such as the input domain) is not correctly written and instead set to 0
.
See read_NNet
for the documentation of the format.
ControllerFormats.FileFormats.write_POLAR
— Functionwrite_POLAR(N::FeedforwardNetwork, filename::String)
Write a neural network to a file in POLAR format.
Input
N
– feedforward neural networkfilename
– name of the output file
Output
nothing
. The network is written to the output file.
ControllerFormats.FileFormats.write_Sherlock
— Functionwrite_Sherlock(N::FeedforwardNetwork, filename::String)
Write a neural network to a file in Sherlock format.
Input
N
– feedforward neural networkfilename
– name of the output file
Output
nothing
. The network is written to the output file.
Notes
The Sherlock format requires that all activation functions are ReLU.