Coder Social home page Coder Social logo

Comments (1)

Koitenshin avatar Koitenshin commented on August 29, 2024 1

TL;DR: After extensive testing I can only recommend:

  1. Image Reward (pain in the butt to install),
  2. score_laion_avs1 (the dataset is far bigger than score_laion-sac-logos-ava-v2),
  3. & score_imclasif-quality-v001 (the new one I am about to tell you about).

I managed to find a new one, that people may or may not like. I personally find it much better than Image Reward score wise, and no weird dependency hoops to jump through to get it installed.

I've tested it with my few best case, middle ground, and worst case images. Noisy images were given low scores; bad images were given low scores; photorealistic bad images were still scored a bit higher but not as high as Image Reward scores them.

I actually had to look up HuggingFace Hub's repo to find out how to get this one to work, as it kept corrupting the downloads or refusing to see the files. I wanted the "model.safetensors" that SFconvertbot issued a pull request for but hadn't been merged yet.

Follow the same instructions as above, but name the folder "imclasif-quality-v001" and the script inside as "score_imclasif-quality-v001.py"

You actually have two options with this scorer:
'good' is super strict and is exactly as I described above, good for making datasets for training.
'normal' gives relatively high scores to everything which means you'll need to use your own discernment more.

If you want the normal option, change 'good' in the script to 'normal'.
Code is as follows:

# based on https://github.com/WhiteWipe/sd-webui-bayesian-merger/blob/main/sd_webui_bayesian_merger/models/ShadowScore.py
import os
import safetensors
import torch

from huggingface_hub import hf_hub_download
from modules import devices
from PIL import Image
from transformers import pipeline, AutoConfig, AutoProcessor, ViTForImageClassification


pathname = hf_hub_download(repo_id="sanali209/imclasif-quality-v001", filename="model.safetensors", revision="eaf21933abb930ac3390a77c2628151afca265f1")

statedict = safetensors.torch.load_file(pathname)

config = AutoConfig.from_pretrained(pretrained_model_name_or_path="sanali209/imclasif-quality-v001")
model = ViTForImageClassification.from_pretrained(pretrained_model_name_or_path=None, state_dict=statedict, config=config)
processor = AutoProcessor.from_pretrained(pretrained_model_name_or_path="sanali209/imclasif-quality-v001")


def score(image, prompt="", use_cuda=True):
    if use_cuda:
        model.to("cuda")
    else:
        model.float()
        model.to("cpu")

    if isinstance(image, Image.Image):
        pil_image = image
    elif isinstance(image, str):
        if os.path.isfile(image):
            pil_image = Image.open(image)
    else:
        pil_image = image

    pipe = pipeline("image-classification", model=model, image_processor=processor, device="cpu" if not use_cuda else "cuda:0")

    score = pipe(images=[pil_image])[0]
    score = [p for p in score if p['label'] == 'good'][0]['score']

    if use_cuda:
        model.to("cpu")
    print(" > score =", score)

    devices.torch_gc()

    return score

from sd-webui-model-mixer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.