linna.utils#

Functions

forward(torch_model, X, layer_idx[, grad])

get_accuracy(loader, model[, size])

param loader:

Data loader

get_counterexamples(original_model, ...[, ...])

Returns the counter examples (w.r.t.

load_experiment(path)

load_model(path)

load_tf_network(file)

Loads a TensorFlow network (.tf file) and returns a PyTorch Sequential neural network

save_results(accuracies, reduction_rates, ...)

writeNNet(weights, biases, inputMins, ...)

Write network data to the .nnet file format :param weights: Weight matrices in the network order :type weights: list :param biases: Bias vectors in the network order :type biases: list :param inputMins: Minimum values for each input :type inputMins: list :param inputMaxes: Maximum values for each input :type inputMaxes: list :param means: Mean values for each input and a mean value for all outputs.

linna.utils.load_tf_network(file: str) torch.nn.Sequential#

Loads a TensorFlow network (.tf file) and returns a PyTorch Sequential neural network

Parameters:

file (str) – File containing TensorFlow network (.tf file)

Returns:

Neural network

Return type:

torch.nn.Sequential

linna.utils.get_accuracy(loader: torch.utils.data.DataLoader, model: torch.nn.Sequential, size=None)#
Parameters:
  • loader (torch.utils.data.DataLoader) – Data loader

  • model (torch.nn.Sequential) – Neural network

  • size (Optional[int]) – Number of inputs to consider

Returns:

Accuracy of network

Return type:

float

linna.utils.load_model(path)#
linna.utils.load_experiment(path)#
linna.utils.save_results(accuracies, reduction_rates, file_name)#
linna.utils.get_counterexamples(original_model, reduced_model, loader, true_label=False)#

Returns the counter examples (w.r.t. classification)

Parameters:
  • original_model

  • reduced_model

  • true_label

Returns:

linna.utils.forward(torch_model, X, layer_idx, grad=False)#
linna.utils.writeNNet(weights, biases, inputMins, inputMaxes, means, ranges, fileName)#

Write network data to the .nnet file format :param weights: Weight matrices in the network order :type weights: list :param biases: Bias vectors in the network order :type biases: list :param inputMins: Minimum values for each input :type inputMins: list :param inputMaxes: Maximum values for each input :type inputMaxes: list :param means: Mean values for each input and a mean value for all outputs. Used to normalize inputs/outputs :type means: list :param ranges: Range values for each input and a range value for all outputs. Used to normalize inputs/outputs :type ranges: list :param fileName: File where the network will be written :type fileName: str