General Utilities#
Classes#
- class Shapes(iterable=(), /)[source]#
Bases:
list[list[int] |list[list[int]]]Shapes list that allows for indexing of multiple shapes.
- get(idx, list_=True)[source]#
Get shape from the shapes list.
- Overloads:
- Parameters:
- idx
int|tuple[int,int] |slice Index of the shape to get, if tuple then first index is the layer index and second is the shape index if the layer has multiple shapes, if slice, returns a Shapes object with the sliced shapes
- list_bool,
Optional If true, returns a list of shapes if the index contains multiple shapes, else returns a single shape, default = True
- idx
- Returns:
- class TypedModuleList(modules=None)[source]#
Bases:
ModuleList,Generic[ModuleT]A typed version of nn.ModuleList that allows for type checking of the modules in the list. See nn.ModuleList for more information.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- append(module)[source]#
Append a given module to the end of the list.
- Args:
module (nn.Module): module to append
Functions#
- ascii_plot(data, *, clear=False, x_num=20, height=6, text='', label='', data2=None)[source]#
Prints a simple ASCII graph of data per index.
- Parameters:
- data
list[float] Data to plot
- clearbool,
Optional If true, clears the previous graph, WARNING: this is very buggy and may not work properly, default = False
- x_num
int,Optional Maximum number of epochs to display in the graph, default = 20
- height
int,Optional Height of the graph in lines, default = 6
- text
str,Optional Optional text to display at the end of the graph
- label
str,Optional Label for the x-axis
- data2
list[float] |NoneType,Optional Secondary data to plot
- data
- check_params(name, supported_params, in_params)[source]#
Checks if provided parameters are supported by the function.
- deep_merge(base, new)[source]#
Performs a deep merge of two dictionaries, equivalent to recursive base | new
- dict_list_append(dict1, dict2, concat=False, balance=False)[source]#
Merges two dictionaries. If a key exists in both dictionaries and not concat, the data type must match. If data type is list or ndarray, the values are extended. If data type is any other type and not concat, the value from the second dictionary overrides the first, else if concat, the values are converted to a list and appended. If balance is True, all lists and ndarrays in each dictionary must have the same length, if a key is missing from one dictionary, it is added with None values to match the length of the other lists/ndarrays in that dictionary.
- Parameters:
- dict1
dict[str,Any] Primary dict to merge secondary dict into
- dict2
dict[str,Any] Secondary dict to merge into primary dict
- concatbool,
Optional If true, concatenates non list/ndarray types instead of overriding them, default = False
- balancebool,
Optional If true, balances the lengths of lists/ndarrays in each dictionary so that each list/ndarray in the returning dictionary has the same length, default = False
- dict1
- Returns:
- get_device()[source]#
Gets the device for PyTorch to use.
- Returns:
tuple[dict[str,Any],torch.device]Arguments for the PyTorch DataLoader to use when loading data into memory and PyTorch device
- label_change(data, in_label, *, one_hot=False, out_label=None)[source]#
Converts an array or tensor of class values to an array or tensor of class indices.
- Parameters:
- data
ArrayT Classes of shape (N) where N is the number of samples
- in_label
ArrayT Unique class values of size (C) where C is the number of classes
- one_hotbool,
Optional If the returned tensor should be 1D array of class indices or 2D one hot tensor if out_label is None or is an int, default = False
- out_label
ArrayT|NoneType,Optional Unique class values of size (C) to transform data into, if None, then values will be indexes
- data
- Returns:
ArrayTndarray or Tensor of class indices of shape (N) and type float, or if one_hot is True, one hot tensor of shape (N,C) and type float
- list_dict_convert(data, balance=False, concat=False)[source]#
Converts a list of dictionaries to a dictionary of lists
- Parameters:
- data
list[dict[str,float|ndarray]] List of dictionaries to convert
- balancebool,
Optional If true, balances the lengths of lists/ndarrays in each dictionary so that each list/ndarray in the returning dictionary has the same length, default = False
- concatbool,
Optional If true, concatenates non list/ndarray types instead of overriding them, default = False
- data
- Returns:
- safe_globals(safe_package, modules, use_all=False, legacy_path_replace=None)[source]#
Adds all classes in the module from the specified package to the list of safe PyTorch classes when loading saved architectures.
- Parameters:
- safe_package
str Package that classes must belong to to be added to the safe globals
- modules
ModuleType|list[ModuleType] Module(s) to add all classes from to the list of safe PyTorch classes when loading saved architectures
- use_allbool,
Optional If true, only adds classes declared in module.__all__, default = False
- legacy_path_replace
tuple[str,str] |NoneType,Optional If not None, replaces the first string with the second string in the module path when adding classes to the safe globals
- safe_package