This repository provides an official implementation of a paper:
"Identification of Novel Modes in Generative Models via Fourier-based Differential Clustering"
Authors: Jingwei Zhang, Mohammad Jalali, Cheuk Ting Li, Farzan Farnia
- Framework: PyTorch, torchvision
- Encoders: clip, torchvision
- Progress bar: tqdm
Pipeline:
- Initialize FINC evaluator
- Select feature extractor (Currently support Inception-V3, DINOv2, CLIP, SwAV, ResNet50)
- Detect novel modes by FINC
from src.metric.FINC import FINC_Evaluator
# Core object for detect novel modes by FINC
evaluator = FINC_Evaluator(logger_path: str, # Path to save log file
batchsize: int, # Batch size
sigma: int, # Bandwidth parameter in RBF kernel
eta: int, # Novelty threshold
num_samples: int, # Sampling number for EACH distribution
result_name: str, # Unique name for saving results
rff_dim: int) # random fourier features dimension to approximate kernel
# Select feature extractor
evaluator.set_feature_extractor(name: str = 'dinov2', # feature extractor ['inception', 'dinov2', 'clip', 'resnet50', 'swav]
save_path: str | None = './save') # Path to save calculated features for reuse
# Extract novel modes of novel_dataset w.r.t. reference dataset by FINC
FINC.rff_differential_clustering_modes_of_dataset(novel_dataset: torch.utils.Dataset,
ref_dataset: torch.utils.Dataset)
In some cases, we may save the extracted features to reduce repeating computation (e.g. tuning bandwidth parameter, novelty threshold). We may specify the folder to save and load features:
evaluator.set_feature_extractor(name = 'dinov2', # feature extractor ['inception', 'dinov2', 'clip', 'swav', 'resnet50']
save_path = './save') # Path to save calculated features for reuse
In this example, the evaluator will first check whether './save/dinov2/[result_name]_[other_information].pt' exists. If not, the evaluator will extract features and their indexes in the dataset, and save to this path.