Skip to content

Calculators

Jordan Welsman edited this page Feb 13, 2023 · 1 revision

nexport.calculate_layers()

This function calculates the number of layers of which a passed model is comprised. Users can select whether to calculate all layers or just the model's hidden layers by specifying whether to include I/O layers via the include_io parameter.

Usage

import nexport

num_layers = nexport.calculate_layers(model=model,
                                      include_io=True
)

Arguments

Argument Data type Default Description
model object Instantiated PyTorch or TensorFlow model
include_io boolean True Whether to include input & output layer in calculation

Accepted arguments

Argument Required Accepted values
model Any fully-connected PyTorch or TensorFlow model
include_io True, False

include_io

This is whether to calculate the neurons which make up the input & output layers of the passed model.

Returns

This function returns an integer representing the number of layers found in the passed model.

Side-effects

This function does not have any side-effects.

nexport.calculate_neurons()

This function calculates the number of total neurons in a passed model. Users can select whether to count all neurons or just those present in the model's hidden layers by specifying whether to include I/O layers via the include_io parameter.

Usage

num_neurons = nexport.calculate_neurons(model=model,
                                        include_io=True
)

Arguments

Argument Data type Default Description
model object Instantiated PyTorch or TensorFlow model
include_io boolean True Whether to include input & output layer in calculation

Accepted arguments

Argument Required Accepted values
model Any fully-connected PyTorch or TensorFlow model
include_io True, False

include_io

This is whether to calculate the neurons which make up the input & output layers of the passed model.

Returns

This function returns an integer representing the number of neurons calculated in the passed model.

Side-effects

This function does not have any side-effects.

nexport.calculate_params()

This function computes the number of trainable parameters of a passed model. Users are able to specify which types of parameters should be returned via the param_type parameter.

Usage

num_params = nexport.calculate_params(model=model,
                                      param_types="wbt"
)

Arguments

Argument Data type Default Description
model object Instantiated PyTorch or TensorFlow model
param_types string wbt Type of parameters to be computed and returned

Accepted arguments

Argument Required Accepted values
model Any fully-connected PyTorch or TensorFlow model
param_types Any combination of w, b, and t

param_types

This is which parameters to include in what is returned by the computation function. The user can specify any combination of w, b, and t, where each respectively represents:

  • w: The neuron weight parameters of the passed model.
  • b: The neuron bias parameters of the passed model.
  • t: The total parameters of the passed model.

Returns

This function returns a list of parameter counts respective to the configuration passed to param_types.

Side-effects

This function does not have any side-effects.