Helpers for importing individual layers

You're likely to want to import parameter values from your trained neural networks from outside of Julia. get_conv_params and get_matrix_params are helper functions enabling you to import individual layers.

Index

Public Interface

MIPVerify.convert_conv_filter_from_fluxMethod
convert_conv_filter_from_flux(filter::Array{T,4}) -> Array{T,4}

Convert a 4D convolution filter from Flux.jl's WHIO convention (width, height, in_channels, out_channels) to MIPVerify's HWIO convention (height, width, in_channels, out_channels).

source
MIPVerify.convert_conv_filter_from_pytorchMethod
convert_conv_filter_from_pytorch(filter::Array{T,4}) -> Array{T,4}

Convert a 4D convolution filter from PyTorch's OIHW convention (out_channels, in_channels, height, width) to MIPVerify's HWIO convention (height, width, in_channels, out_channels).

source
MIPVerify.convert_images_from_fluxMethod
convert_images_from_flux(images::Array{T,4}) -> Array{T,4}

Convert a batch of images from Flux.jl's WHCN convention (width, height, channels, num_samples) to MIPVerify's NHWC convention (num_samples, height, width, channels).

source
MIPVerify.convert_images_from_pytorchMethod
convert_images_from_pytorch(images::Array{T,4}) -> Array{T,4}

Convert a batch of images from PyTorch's NCHW convention (num_samples, channels, height, width) to MIPVerify's NHWC convention (num_samples, height, width, channels).

source
MIPVerify.convert_linear_weights_from_pytorchMethod
convert_linear_weights_from_pytorch(matrix::Array{T,2}) -> Array{T,2}

Convert a weight matrix from PyTorch's (out_features, in_features) convention to MIPVerify's (in_features, out_features) convention.

source
MIPVerify.get_conv_paramsMethod
get_conv_params(
    param_dict,
    layer_name,
    expected_size;
    matrix_name,
    bias_name,
    expected_stride,
    padding
)

Helper function to import the parameters for a convolution layer from param_dict as a Conv2d object.

The default format for the key is 'layer_name/weight' and 'layer_name/bias'; you can customize this by passing in the named arguments matrix_name and bias_name respectively. The expected parameter names will then be 'layer_name/matrix_name' and 'layer_name/bias_name'

Arguments

  • param_dict::Dict{String}: Dictionary mapping parameter names to array of weights / biases.
  • layer_name::String: Identifies parameter in dictionary.
  • expected_size::NTuple{4, Int}: Tuple of length 4 corresponding to the expected size of the weights of the layer, in HWIO order: (filter_height, filter_width, in_channels, out_channels).
source
MIPVerify.get_matrix_paramsMethod
get_matrix_params(
    param_dict,
    layer_name,
    expected_size;
    matrix_name,
    bias_name
)

Helper function to import the parameters for a layer carrying out matrix multiplication (e.g. fully connected layer / softmax layer) from param_dict as a Linear object.

The default format for the key is 'layer_name/weight' and 'layer_name/bias'; you can customize this by passing in the named arguments matrix_name and bias_name respectively. The expected parameter names will then be 'layer_name/matrix_name' and 'layer_name/bias_name'

Arguments

  • param_dict::Dict{String}: Dictionary mapping parameter names to array of weights / biases.
  • layer_name::String: Identifies parameter in dictionary.
  • expected_size::NTuple{2, Int}: Tuple of length 2 corresponding to the expected size of the weights of the layer, in (in_features, out_features) order.
source

Internal