๐จ NIMA Regression (Finetuned)
์ด ๋ชจ๋ธ์ ResNet18์ ๊ธฐ๋ฐ์ผ๋ก ํ NIMA ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ์ฌ,eungyukm/image-manual-label
๋ฐ์ดํฐ์
์ผ๋ก ์ง์ ์๋ ํ๊ฐํ ์ด๋ฏธ์ง ์ ์๋ฅผ ํ์ตํ ํ๊ท ๋ชจ๋ธ์
๋๋ค.
- ์ ๋ ฅ: RGB ์ด๋ฏธ์ง (224x224)
- ์ถ๋ ฅ: ์์ธก๋ ๋ฏธ์ ์ ์ (float, 1.0 ~ 10.0)
- ๋ชฉ์ : ์ด๋ฏธ์ง์ aesthetic quality ํ๊ฐ
๐ ์ฌ์ฉ๋ฒ (Hugging Face์์ ๋ฐ๋ก ๋ค์ด๋ก๋ํ์ฌ ์ถ๋ก )
import torch
import torch.nn as nn
from torchvision import transforms
from torchvision.models import resnet18
from PIL import Image
from huggingface_hub import hf_hub_download
# 1. ๋ชจ๋ธ ์ ์
class NIMARegression(nn.Module):
def __init__(self):
super().__init__()
self.base_model = resnet18(weights="IMAGENET1K_V1")
self.base_model.fc = nn.Identity()
self.head = nn.Sequential(
nn.Linear(512, 256),
nn.ReLU(),
nn.Dropout(0.5),
nn.Linear(256, 1)
)
def forward(self, x):
x = self.base_model(x)
return self.head(x).squeeze(1)
# 2. ๋ชจ๋ธ ๊ฐ์ค์น ๋ค์ด๋ก๋ (Hugging Face์์)
model_path = hf_hub_download(
repo_id="eungyukm/nima_finetuned",
filename="nima_finetuned.pth"
)
# 3. ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ ๋ฐ ์ ์ฒ๋ฆฌ
image = Image.open("example.jpg").convert("RGB")
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406],
[0.229, 0.224, 0.225])
])
input_tensor = transform(image).unsqueeze(0)
# 4. ๋ชจ๋ธ ๋ก๋ ๋ฐ ์ถ๋ก
model = NIMARegression()
model.load_state_dict(torch.load(model_path, map_location="cpu"))
model.eval()
with torch.no_grad():
score = model(input_tensor).item()
print(f"์์ธก๋ ๋ฏธ์ ์ ์: {score:.2f}")
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
๐
Ask for provider support