File IO

Input Bounds

omlt.io.input_bounds.load_input_bounds(input_bounds_filename)[source]

Read the input bounds from the given file.

omlt.io.input_bounds.write_input_bounds(input_bounds_filename, input_bounds)[source]

Write the specified input bounds to the given file.

Keras Reader

omlt.io.keras_reader.load_keras_sequential(nn, scaling_object=None, scaled_input_bounds=None)[source]

Load a keras neural network model (built with Sequential) into an OMLT network definition object. This network definition object can be used in different formulations.

Parameters
  • nn (keras.model) – A keras model that was built with Sequential

  • scaling_object (instance of ScalingInterface or None) – Provide an instance of a scaling object to use to scale iputs –> scaled_inputs and scaled_outputs –> outputs. If None, no scaling is performed. See scaling.py.

  • scaled_input_bounds (dict or None) – A dict that contains the bounds on the scaled variables (the direct inputs to the neural network). If None, then no bounds are specified.

Return type

NetworkDefinition

ONNX

omlt.io.onnx.load_onnx_neural_network(onnx, scaling_object=None, input_bounds=None)[source]

Load a NetworkDefinition from an onnx object.

Parameters
  • onnx – onnx model

  • scaling_object (instance of object supporting ScalingInterface) –

  • input_bounds (list of tuples) –

Return type

NetworkDefinition

omlt.io.onnx.load_onnx_neural_network_with_bounds(filename)[source]

Load a NetworkDefinition with input bounds from an onnx object.

Parameters

filename (str) – the path where the ONNX model and input bounds file are written

Return type

NetworkDefinition

omlt.io.onnx.write_onnx_model_with_bounds(filename, onnx_model=None, input_bounds=None)[source]

Write the ONNX model to the given file.

If input_bounds is not None, write it alongside the ONNX model.

Parameters
  • filename (str) – the path where the ONNX model is written

  • onnx_model (onnx model or None) – the onnx model

  • input_bounds (None or dict-like or list) – bounds on the input variables

class omlt.io.onnx_parser.NetworkParser[source]

Bases: object

References

parse_network(graph, scaling_object, input_bounds)[source]