Metric Utils#
- class cdfvd.utils.metric_utils.FeatureStats[source]#
Class to store statistics of features, including all features and mean/covariance.
- Parameters:
capture_all – Whether to store all the features.
capture_mean_cov – Whether to store mean and covariance.
max_items – Maximum number of items to store.
- set_num_features(num_features: int)[source]#
Set the number of features diminsions.
- Parameters:
num_features (int) – Number of features diminsions.
- is_full() bool [source]#
Check if the maximum number of samples is reached.
- Returns:
True if the storage is full, False otherwise.
- Return type:
bool
- append(x: ndarray)[source]#
Add the newly computed features to the list. Update the mean and covariance.
- Parameters:
x (ndarray) – New features to record.
- append_torch(x: Tensor, rank: int, num_gpus: int)[source]#
Add the newly computed PyTorch features to the list. Update the mean and covariance.
- Parameters:
x (Tensor) – New features to record.
rank (int) – Rank of the current GPU.
num_gpus (int) – Total number of GPUs.
- get_all() ndarray [source]#
Get all the stored features as NumPy Array.
- Returns:
Concatenation of the stored features.
- Return type:
ndarray
- get_all_torch() Tensor [source]#
Get all the stored features as PyTorch Tensor.
- Returns:
Concatenation of the stored features.
- Return type:
Tensor
- get_mean_cov() Tuple[ndarray, ndarray] [source]#
Get the mean and covariance of the stored features.
- Returns:
Mean and covariance of the stored features.
- Return type:
Tuple[ndarray, ndarray]
- save(pkl_file: str)[source]#
Save the features and statistics to a pickle file.
- Parameters:
pkl_file (str) – Path to the pickle file.
- static load(pkl_file: str) FeatureStats [source]#
Load the features and statistics from a pickle file.
- Parameters:
pkl_file (str) – Path to the pickle file.
- Return type: