from PIL import Image
import numpy as np
import torch
from transformers import (
AutoImageProcessor,
AutoModelForImageClassification,
)
MODEL_NAME = "p1atdev/wd-swinv2-tagger-v3-hf"
model = AutoModelForImageClassification.from_pretrained(
MODEL_NAME,
)
processor = AutoImageProcessor.from_pretrained(MODEL_NAME, trust_remote_code=True)
image = Image.open("sample.webp")
inputs = processor.preprocess(image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs.to(model.device, model.dtype))
logits = torch.sigmoid(outputs.logits[0]) # take the first logits# get probabilities
results = {model.config.id2label[i]: logit.float() for i, logit inenumerate(logits)}
results = {
k: v for k, v insorted(results.items(), key=lambda item: item[1], reverse=True) if v > 0.35# 35% threshold
}
print(results) # rating tags and character tags are also included#{'1girl': tensor(0.9974),# 'solo': tensor(0.9720),# 'dress': tensor(0.9539),# 'hat': tensor(0.9512),# 'outdoors': tensor(0.9439),# ...
Accelerate with 🤗 Optimum
Maybe about 30% faster and about 50% light weight model size than transformers version, but the accuracy is slightly degraded.
wd-swinv2-tagger-v3-hf huggingface.co is an AI model on huggingface.co that provides wd-swinv2-tagger-v3-hf's model effect (), which can be used instantly with this p1atdev wd-swinv2-tagger-v3-hf model. huggingface.co supports a free trial of the wd-swinv2-tagger-v3-hf model, and also provides paid use of the wd-swinv2-tagger-v3-hf. Support call wd-swinv2-tagger-v3-hf model through api, including Node.js, Python, http.
wd-swinv2-tagger-v3-hf huggingface.co is an online trial and call api platform, which integrates wd-swinv2-tagger-v3-hf's modeling effects, including api services, and provides a free online trial of wd-swinv2-tagger-v3-hf, you can try wd-swinv2-tagger-v3-hf online for free by clicking the link below.
p1atdev wd-swinv2-tagger-v3-hf online free url in huggingface.co:
wd-swinv2-tagger-v3-hf is an open source model from GitHub that offers a free installation service, and any user can find wd-swinv2-tagger-v3-hf on GitHub to install. At the same time, huggingface.co provides the effect of wd-swinv2-tagger-v3-hf install, users can directly use wd-swinv2-tagger-v3-hf installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
wd-swinv2-tagger-v3-hf install url in huggingface.co: