Tensorflow Custom

The tensorflow custom (tfcustom) module contains functions that process models created with the tensorflow package.

Feature Processing (tfcustom.fts)

Contains functions to extract features from a tensorflow neural network

fns.tfcustom.fts.feature_extractor(model, lay, model_in, norm)

Function to extract the features from a given layer of a model

Parameters
  • model (loaded keras model) –

  • lay (str) – name of a layer in model

  • model_in (varies) – correctly formatted model input

  • norm (str) – {‘ft01’, ‘all01’, ‘none’} a string to indicate which normalization methodology to use;

Returns

ft_mat (np.ndarray[(any, any, any), float]) – an array of all features extracted from a given layer; the first two dimensions are the size of the feature; the last dimension is the number of features in a layer

See also

fns.mat.normalize_mat() for information about choices for norm

fns.tfcustom.fts.parse_features(model, lay, features)

Function to make a list of the features to plot

Prints error message and exits program for features = [‘Grid’]

Parameters
  • model (loaded keras model) –

  • lay (str) – name of a layer in model features (list[str]): list of features to plot, starting at feature 1

  • features (list[str]) –

Returns
  • n_features (int) – how may features to plot

  • features (list[int]) – list of features to plot, starting at feature 0

Model Prints (tfcustom.prints)

Contains functions to print out lists of options for model-related input arguments

fns.tfcustom.prints.print_layers(model)

Function that prints a list of layer names in a model

Parameters

model (loaded keras model) –

Returns

No Return Objects

fns.tfcustom.prints.print_features(model, lay)

Function that prints how many features are extracted from a layer of a model

Parameters
  • model (loaded keras model) –

  • lay (str) – name of layer to get features from

Returns

No Return Objects

Model Checks (tfcustom.checks)

Contains functions to check that the model-related input arguments passed are valid

fns.tfcustom.checks.check_layer(model, lay)

Function that checks if a layer name is in the model

Parameters
  • model (loaded keras model) –

  • lay (str) – name of layer to test

Returns

No Return Objects

fns.tfcustom.checks.check_features(model, lay, features)

Function that checks if number of features requested are available from a layer

Parameters
  • model (loaded keras model) –

  • lay (str) – name of layer where features will be extracted from

  • features (list[str]) – should be [‘Grid’], [‘All’], or a list of integers; features the script plans on extracting

Returns

No Return Objects

Calico Functions (tfcustom.calico)

Contains functions to create a calico network and do prints/checks on the calcio network inputs

fns.tfcustom.calico.check_calico_layer(model, lay, branch='None', catlay='None')

Function that checks if the layer is a valid selection for the split layer

Parameters
  • model (loaded keras model) –

  • lay (str) – name of layer to test

  • branch (str) – key used to identify which layers are on the secondary branch; use ‘None’ if the model only has one branch

  • catlay (str) – name of layer where the branches of the model are concatenated use ‘None’ if the model only has one branch

Returns

No Return Objects

fns.tfcustom.calico.check_calico_features(model, lay, features)

Function that checks if number of features requested are available from a layer

Parameters
  • model (loaded keras model) –

  • lay (str) – name of layer where features will be extracted from

  • features (str) – an integer; features the calico model scales

Returns

No Return Objects

fns.tfcustom.calico.layer_copy(cnnlayer, tag)

Function to create a copy of a keras layer object

Based on the layer type and configuration

Does NOT copy trained layer weights

Parameters
  • cnnlayer (keras.layers) – layer to make a copy of

  • tag (str) – string “tag” to be appended to the name of the copied layer

Returns

cnnlayer2 (keras.layer) – copy of cnnlayer with same type and configuration