FileFormats module

Reading neural networks

ControllerFormats.FileFormats.read_MATFunction
read_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 the MAT file
  • act_key – key used for the activation functions
  • net_key – (optional; default: nothing) key used for the neural network

Output

A FeedforwardNetwork.

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_NNetFunction
read_NNet(filename::String)

Read a neural network stored in NNet format.

Input

  • filename – name of the NNet file

Output

A FeedforwardNetwork.

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):

  1. Header text, each line beginning with "//"
  2. Comma-separated line with four values: number of layer operations, number of inputs, number of outputs, maximum layer size
  3. Comma-separated line with the layer sizes
  4. Flag that is no longer used
  5. Minimum values of inputs
  6. Maximum values of inputs
  7. Mean values of inputs and one value for all outputs
  8. Range values of inputs and one value for all outputs
  9. 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_ONNXFunction
read_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 the ONNX file
  • input_dimension – (optional; default: nothing) input dimension (required by ONNX.jl parser); see the notes below

Output

A FeedforwardNetwork.

Notes

This implementation assumes the following structure:

  1. First comes the input vector (which is ignored).
  2. Next come the weight matrices W (transposed) and bias vectors b in pairs in the order in which they are applied.
  3. 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_POLARFunction
read_POLAR(filename::String)

Read a neural network stored in POLAR format.

Input

  • filename – name of the POLAR file

Output

A FeedforwardNetwork.

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.

Writing neural networks

ControllerFormats.FileFormats.write_NNetFunction
write_NNet(N::FeedforwardNetwork, filename::String)

Write a neural network to a file in NNet format.

Input

  • N – feedforward neural network
  • filename – 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_POLARFunction
write_POLAR(N::FeedforwardNetwork, filename::String)

Write a neural network to a file in POLAR format.

Input

  • N – feedforward neural network
  • filename – name of the output file

Output

nothing. The network is written to the output file.

ControllerFormats.FileFormats.write_SherlockFunction
write_Sherlock(N::FeedforwardNetwork, filename::String)

Write a neural network to a file in Sherlock format.

Input

  • N – feedforward neural network
  • filename – 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.