torchsig.models.model_utils.layer_toolsΒΆ

Functions

get_layer_list

returns a list of all layers in the input model, including layers in any nested models therein layers are listed in forward-pass order

is_same_type

returns True if layer1 and layer2 are of the same type; false otherwise if a class is input as layer2 [e.g., is_same_type(my_conv_layer, Conv2d) ], the type defined by the class is used if a string is input as layer2, the string is matched to the name of the class of layer1

replace_layer

search through model until old_layer is found, and replace it with new layer; returns True is old_layer was found; False otherwise

replace_layers_of_type

search through model finding all layers L of type layer_type and replace with new_layer_factory_fn(L) returns true if at least one layer was replaced; false otherwise

replace_layers_of_types

search through model finding all layers L such that for some ordered pair [layer_type, new_layer_factory_fn] in type_factory_pairs, L is of type layer_type, and replace with new_layer_factory_fn(L) returns true if at least one layer was replaced; false otherwise

replace_layers_on_condition

search through model finding all layers L such that conditional_fn(L), and replace them with new_layer_factory_fn(L) returns true if at least one layer was replaced; false otherwise

replace_layers_on_conditions

search through model finding all layers L such that for some ordered pair [conditional_fn, new_layer_factory_fn] in condition_factory_pairs, conditional_fn(L), and replace them with new_layer_factory_fn(L) layers will only be replaced once, so the first conditional for which a layer returns true will be last conditional to which it is compared returns true if at least one layer was replaced; false otherwise

same_type_fn

curried version of is_same_type; returns a function f such than f(layer2) <-> is_same_type(layer1, layer2)