CLIP Maximum Mean Discrepancy (CMMD) for evaluating generative models
Project description
CLIP-MMD
An unofficial implementation of Rethinking FID: Towards a Better Evaluation Metric for Image Generation. Uses Transformers on PyTorch.
Features
- support multiple GPUs with DDP.
- acquire less memory; support larger dataset (like 1M each).
- uses resizer of PIL for more accurate results, recommended by Clean-FID.
- support multiple input: folder, Dataset(for calculation during training), pre-computed stastics.
Comparison
Measure time (second) of calculation. Cuda is on single V100.
n, m, dim | original | efficient | (by row) | (cuda) | (cuda + by row) |
---|---|---|---|---|---|
2048, 16384, 768 | 1.379 | 1.142 | 0.421 | 0.460 | 0.164 |
16384, 16384, 768 | 3.312 | 2.764 | 1.137 | 0.567 | 0.391 |
50000, 50000, 768 | 29.74 | 26.64 | 12.85 | 1.413 | 1.383 |
1280000, 50000, 768 | OOM | OOM | 98.21 | OOM | 4.446 |
Thanks
To cmmd-pytorch. Some logics came from it.
Usage
pip install clip-mmd
CLI interface
usage: clip-mmd [-h] [--no-cuda] [--gpus GPUS] [--no-mem-save] [--batch-size BATCH_SIZE] [--calculator-bs CALCULATOR_BS] [--model MODEL] [--num-workers NUM_WORKERS] [--extract-mode] [--size SIZE]
[--interpolation {nearest,bilinear,bicubic,lanczos,hamming,box}]
data_path_1 [data_path_2]
Command Line Interface for CMMD calculations and feature extraction.
positional arguments:
data_path_1 Path to the first data folder or file
data_path_2 Path to the second data folder or file, or output path of pre-extracted features
options:
-h, --help show this help message and exit
--no-cuda only use cpu
--gpus GPUS Comma-separated list of GPUs to use (e.g., 0,1,2,3). Use it if you want do on multi gpus.
--no-mem-save Flag to disable memory-saving features
--batch-size BATCH_SIZE
Batch size for processing
--calculator-bs CALCULATOR_BS
Batch size for the CMMD calculator
--model MODEL Model to use for feature extraction. Default: openai/clip-vit-large-patch14-336,
--num-workers NUM_WORKERS
Numbers of dataloader workers
--extract-mode If enabled, only extract reatures from data_path_1, and save to data_path_2.
--size SIZE Image patch size for model input
--interpolation {nearest,bilinear,bicubic,lanczos,hamming,box}
Interpolation algorithm for resampling an image. Default: bicubic.
example
clip-mmd /path/to/generated_samples.npz /path/to/reference/imgs/
clip-mmd /path/to/images/ features/for/them.pth --gpus 3,4,5,6 --batch-size 128 --extract-mode
clip-mmd /path/to/features1.pth /path/to/features2.pth
clip-mmd /folder/1 /folder/2 --interpolation bilinear
clip-mmd /pre/extracted/features.pth /sampled/images
OR directly use it:
from clip_mmd import logic
prep = logic.CMMD(data_parallel=True, device=[2,3,4,5])
distance = prep.execute('path/to/folder/1', 'path/to/folder/2')
print(f'CMMD: {distance:5f}')
You can also use path to sampled npz or pth, pre-caculated statics, or even customized Dataset.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
clip-mmd-0.0.2.tar.gz
(12.8 kB
view details)
Built Distribution
clip_mmd-0.0.2-py3-none-any.whl
(13.2 kB
view details)
File details
Details for the file clip-mmd-0.0.2.tar.gz
.
File metadata
- Download URL: clip-mmd-0.0.2.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dde0289b363d7cd494abf29acf4420fdd744778839df7d9058790ec2148a2e6f |
|
MD5 | 6f84c97ed88f34739e3eeff384f3457f |
|
BLAKE2b-256 | d598744b217b42dc86ef8a40a6ad5891b10460ec9a58d428f215fa12ddd92931 |
File details
Details for the file clip_mmd-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: clip_mmd-0.0.2-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50639cc6311f624ba4108527ffec885bf6a4ced860c43a446a86549bd895e2af |
|
MD5 | 5fb20968c9f4b10d2442c125fd39681f |
|
BLAKE2b-256 | 0fbde0ec57a9157c58f9606471a7980d9290482ed1538f306657b0e86f9fdb3d |