Utils
Individual_helper
- gaggle.utils.individual_helper.from_gene_pool(gene_pool: dict) -> (<class 'torch.Tensor'>, tuple[list, list])[source]
From a gene_pool generates a flattened tensor that contains all the params of the gene_pool as well as metadata to be passed to from_tensor to recreate the gene_pool after any modification to the newly created flattened tensor.
- Parameters:
gene_pool – dictionary of parameters that defines an Individual.
- Returns:
Flattened gene tensor and a metadata tuple.
- gaggle.utils.individual_helper.from_gene_pool_no_metadata(gene_pool: dict) Tensor [source]
Same as from_gene_pool but does return the metadata. It is used in cases where we do not care about transforming the tensor back into the gene pool (for example metric computation on the gene pool).
- Parameters:
gene_pool –
- Returns:
Flattened gene tensor.
- gaggle.utils.individual_helper.from_tensor(gene_pool: dict, tensor: Tensor, metadata: tuple[list, list]) dict [source]
Updates the parameters in gene_pool from the flattened tensor tensor inplace.
- Parameters:
gene_pool – dictionary of parameters that defines an Individual.
tensor – the flattened tensor of weights that will be transformed into the gene_pool.
metadata – the metadata that was acquired when originally running from_gene_pool on gene_pool to get the tensor.
- Returns:
The modified gene_pool dictionary
Notes
It applies the transformation of the gene_pool inplace on the gene_pool argument (even though it still returns it)
Metrics
Numpy_helper
Smooth_value
- class gaggle.utils.smooth_value.SmoothedValue(window_size: int = 10, fmt: str = '{avg:.3f}')[source]
Bases:
object
Track a series of values and provide access to smoothed values over a window or the global series average.
- property avg: float
- property global_avg: float
- property max: float
- property median: float
- property min: float
- property value: float
Special_images
Special_print
- class gaggle.utils.special_print.bcolors[source]
Bases:
object
- BOLD = '\x1b[1m'
- ENDC = '\x1b[0m'
- FAIL = '\x1b[91m'
- HEADER = '\x1b[95m'
- OKBLUE = '\x1b[94m'
- OKCYAN = '\x1b[96m'
- OKGREEN = '\x1b[92m'
- UNDERLINE = '\x1b[4m'
- WARNING = '\x1b[93m'
- gaggle.utils.special_print.print_dict_highlighted(content: dict, title=None, color='\x1b[92m')[source]
- gaggle.utils.special_print.print_highlighted(content, color='\x1b[92m')[source]
Prints a highlighted message separated by dashes
content