Merge pull request #388 from modelscope/preference_model

Preference model
This commit is contained in:
Zhongjie Duan
2025-03-02 19:56:00 +08:00
committed by GitHub
40 changed files with 7006 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
# Image Quality Metric
The image quality assessment functionality has been integrated into Diffsynth. We support the following models:
* [ImageReward](https://github.com/THUDM/ImageReward)
* [Aesthetic](https://github.com/christophschuhmann/improved-aesthetic-predictor)
* [PickScore](https://github.com/yuvalkirstain/pickscore)
* [CLIP](https://github.com/openai/CLIP)
* [HPSv2](https://github.com/tgxs002/HPSv2)
* [HPSv2.1](https://github.com/tgxs002/HPSv2)
* [MPS](https://github.com/Kwai-Kolors/MPS)
## Usage
See [`./image_quality_evaluation.py`](./image_quality_evaluation.py) for more details.

View File

@@ -0,0 +1,23 @@
from diffsynth.extensions.ImageQualityMetric import download_preference_model, load_preference_model
from modelscope import dataset_snapshot_download
from PIL import Image
# Download example image
dataset_snapshot_download(
dataset_id="DiffSynth-Studio/examples_in_diffsynth",
allow_file_pattern="data/examples/ImageQualityMetric/image.jpg",
local_dir="./"
)
# Parameters
prompt = "an orange cat"
image = Image.open("data\examples\ImageQualityMetric\image.jpg")
device = "cuda"
cache_dir = "./models"
# Run preference models
for model_name in ["ImageReward", "Aesthetic", "PickScore", "CLIP", "HPSv2", "HPSv2.1", "MPS"]:
path = download_preference_model(model_name, cache_dir=cache_dir)
preference_model = load_preference_model(model_name, device=device, path=path)
print(model_name, preference_model.score(image, prompt))