Download examples/image_quality_metric/lpips.py from ymyy307/diffsynth: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/ymyy307/diffsynth/resolve/main/examples/image_quality_metric/lpips.py
- Command line
-
hf download hf://ymyy307/diffsynth/examples/image_quality_metric/lpips.py
-
curl -L -o lpips.py https://huggingface.co/ymyy307/diffsynth/resolve/main/examples/image_quality_metric/lpips.py
1.27 kB
| from diffsynth.metrics import LPIPSMetric, ModelConfig | |
| from modelscope import dataset_snapshot_download | |
| dataset_snapshot_download( | |
| "DiffSynth-Studio/diffsynth_example_dataset", | |
| allow_file_pattern=["flux/FLUX.1-dev/*", "flux2/FLUX.2-dev/*"], | |
| local_dir="./data/diffsynth_example_dataset", | |
| ) | |
| # net="alex" with LPIPS/alexnet.safetensors (default) | |
| # For VGG: net="vgg", model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="LPIPS/vgg.safetensors") | |
| # For SqueezeNet: net="squeeze", model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="LPIPS/squeezenet.safetensors") | |
| metric = LPIPSMetric.from_pretrained( | |
| net="alex", | |
| model_config=ModelConfig( | |
| model_id="DiffSynth-Studio/ImageMetrics", | |
| origin_file_pattern="LPIPS/alexnet.safetensors", | |
| ), | |
| device="cuda", | |
| target_size=512, | |
| ) | |
| score = metric.compute( | |
| "./data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg", | |
| "./data/diffsynth_example_dataset/flux/FLUX.1-dev/2.jpg", | |
| ) | |
| print(f"LPIPS score (image vs image): {score:.4f}") | |
| score = metric.compute( | |
| "./data/diffsynth_example_dataset/flux/FLUX.1-dev", | |
| "./data/diffsynth_example_dataset/flux2/FLUX.2-dev", | |
| ) | |
| print(f"LPIPS score (dir vs dir): {score:.4f}") | |