๐ŸŽจ 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}")
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Dataset used to train eungyukm/nima_finetuned