Spaces:
Sleeping
Sleeping
Evan Li commited on
Commit ·
b670fec
1
Parent(s): 8f19f34
beauty analyzer
Browse files- .gitignore +2 -0
- analyzers/beauty_analyzer.py +9 -2
.gitignore
CHANGED
|
@@ -5,3 +5,5 @@ __pycache__/
|
|
| 5 |
# Virtual environments
|
| 6 |
.venv/
|
| 7 |
venv/
|
|
|
|
|
|
|
|
|
| 5 |
# Virtual environments
|
| 6 |
.venv/
|
| 7 |
venv/
|
| 8 |
+
|
| 9 |
+
*.pt
|
analyzers/beauty_analyzer.py
CHANGED
|
@@ -29,6 +29,11 @@ Inputs
|
|
| 29 |
------
|
| 30 |
img_rgb : np.ndarray (H, W, 3) uint8
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
Outputs (dict)
|
| 33 |
--------------
|
| 34 |
beauty_score : float in [1.0, 5.0] (SCUT-FBP5500 native range)
|
|
@@ -58,6 +63,8 @@ LOCAL_WEIGHTS_PATH = os.environ.get(
|
|
| 58 |
HF_REPO_ID = os.environ.get("BEAUTY_HF_REPO_ID") # e.g. "user/scut-fbp5500-resnet50"
|
| 59 |
HF_FILENAME = os.environ.get("BEAUTY_HF_FILENAME", "beauty_regressor.pt")
|
| 60 |
BACKBONE = os.environ.get("BEAUTY_BACKBONE", "resnet50")
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# Standard ImageNet stats — SCUT-FBP5500 fine-tunes from ImageNet-pretrained
|
| 63 |
# backbones so we use the same normalisation at inference time.
|
|
@@ -104,9 +111,9 @@ class BeautyAnalyzer:
|
|
| 104 |
self.model.load_state_dict(state, strict=True)
|
| 105 |
self.model.to(self.device).eval()
|
| 106 |
|
| 107 |
-
#
|
| 108 |
self.transform = transforms.Compose([
|
| 109 |
-
transforms.Resize((
|
| 110 |
transforms.ToTensor(),
|
| 111 |
transforms.Normalize(mean=IMAGENET_MEAN, std=IMAGENET_STD),
|
| 112 |
])
|
|
|
|
| 29 |
------
|
| 30 |
img_rgb : np.ndarray (H, W, 3) uint8
|
| 31 |
|
| 32 |
+
Inference resolution is ``BEAUTY_IMG_SIZE`` (default 224). If you trained
|
| 33 |
+
with ``--img-size 256`` (the Hyak ``train.slurm`` default), set
|
| 34 |
+
``BEAUTY_IMG_SIZE=256`` in the face-service environment so preprocessing
|
| 35 |
+
matches the checkpoint.
|
| 36 |
+
|
| 37 |
Outputs (dict)
|
| 38 |
--------------
|
| 39 |
beauty_score : float in [1.0, 5.0] (SCUT-FBP5500 native range)
|
|
|
|
| 63 |
HF_REPO_ID = os.environ.get("BEAUTY_HF_REPO_ID") # e.g. "user/scut-fbp5500-resnet50"
|
| 64 |
HF_FILENAME = os.environ.get("BEAUTY_HF_FILENAME", "beauty_regressor.pt")
|
| 65 |
BACKBONE = os.environ.get("BEAUTY_BACKBONE", "resnet50")
|
| 66 |
+
# Must match training `--img-size` (224 for older checkpoints, 256 for newer Hyak recipe).
|
| 67 |
+
BEAUTY_IMG_SIZE = int(os.environ.get("BEAUTY_IMG_SIZE", "256"))
|
| 68 |
|
| 69 |
# Standard ImageNet stats — SCUT-FBP5500 fine-tunes from ImageNet-pretrained
|
| 70 |
# backbones so we use the same normalisation at inference time.
|
|
|
|
| 111 |
self.model.load_state_dict(state, strict=True)
|
| 112 |
self.model.to(self.device).eval()
|
| 113 |
|
| 114 |
+
# Inference resize must match training `--img-size` (see BEAUTY_IMG_SIZE).
|
| 115 |
self.transform = transforms.Compose([
|
| 116 |
+
transforms.Resize((BEAUTY_IMG_SIZE, BEAUTY_IMG_SIZE)),
|
| 117 |
transforms.ToTensor(),
|
| 118 |
transforms.Normalize(mean=IMAGENET_MEAN, std=IMAGENET_STD),
|
| 119 |
])
|