File size: 2,293 Bytes
e3a5cea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os

class Config:
    # ── Paths ──────────────────────────────────────────────────────────────
    ROOT_DIR        = os.path.dirname(os.path.abspath(__file__))
    DATA_DIR        = os.path.join(ROOT_DIR, "data")
    UTKFACE_DIR     = os.path.join(DATA_DIR, "UTKFace")
    MODEL_DIR       = os.path.join(ROOT_DIR, "models")
    MODEL_PATH      = os.path.join(MODEL_DIR, "face_model.pth")
    BEST_MODEL_PATH = os.path.join(MODEL_DIR, "face_model_best.pth")

    # ── Dataset ────────────────────────────────────────────────────────────
    # UTKFace filename: [age]_[gender]_[race]_[datetime].jpg
    # Race codes: 0=White, 1=Black, 2=Asian, 3=Indian, 4=Others
    TARGET_RACES  = [0, 1, 3]   # White + Black (β‰ˆUS), Indian
    MIN_AGE       = 1
    MAX_AGE       = 90
    TRAIN_RATIO   = 0.80
    VAL_RATIO     = 0.10
    # remaining 0.10 β†’ test

    # ── Training ───────────────────────────────────────────────────────────
    IMG_SIZE      = 224
    BATCH_SIZE    = 32
    NUM_EPOCHS    = 30
    LR            = 1e-4
    LR_STEP       = 10        # StepLR step size
    LR_GAMMA      = 0.5
    WEIGHT_DECAY  = 1e-4
    PATIENCE      = 7         # early-stopping patience
    NUM_WORKERS   = 4
    SEED          = 42

    # Loss weights (gender is classification; age is regression normalised 0-1)
    GENDER_LOSS_WEIGHT = 1.0
    AGE_LOSS_WEIGHT    = 5.0   # scale up because MAE lives in [0,1]

    # ── Labels ─────────────────────────────────────────────────────────────
    GENDER_LABELS = ["Male", "Female"]

    # ── Inference ──────────────────────────────────────────────────────────
    FACE_CONFIDENCE = 0.7     # minimum face-detection confidence