1import torch
2
3model = torch.jit.load("nima_scorer.pt")
4model.eval()
-
Resize so the shorter side is 224, using BICUBIC interpolation
-
Center crop to 224×224
-
Convert to a PyTorch tensor
-
Normalize using:
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
This matches standard ImageNet preprocessing.
The model outputs a 10-element vector corresponding to the predicted distribution over scores from 1 to 10.
You can compute the mean aesthetic score like this:
1import torch
2
3scores = model(image)[0] # shape: [10]
4ratings = torch.arange(1, 11, dtype=torch.float)
5mean_score = (scores * ratings).sum().item()