mirror of
https://github.com/modelscope/DiffSynth-Studio.git
synced 2026-03-18 22:08:13 +00:00
Merge pull request #388 from modelscope/preference_model
Preference model
This commit is contained in:
15
examples/image_quality_metric/README.md
Normal file
15
examples/image_quality_metric/README.md
Normal 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.
|
||||
23
examples/image_quality_metric/image_quality_evaluation.py
Normal file
23
examples/image_quality_metric/image_quality_evaluation.py
Normal 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))
|
||||
Reference in New Issue
Block a user