Spaces:
Sleeping
Sleeping
k22056537 commited on
Commit Β·
f85441f
1
Parent(s): 645ffe4
refactor: single checkpoints/ dir, fix uvicorn cmd and hybrid config path
Browse filesFiles changed (7)
39 unmodified lines4041424344454639 unmodified lines**Web application (API + frontend):**```bashuvicorn app:app --host 0.0.0.0 --port 7860```Open http://localhost:7860 in a browser.39 unmodified lines4041424344454639 unmodified lines**Web application (API + frontend):**```bashuvicorn main:app --host 0.0.0.0 --port 7860```Open http://localhost:7860 in a browser.
12 unmodified lines13141516171819202122232412 unmodified linesfeature_selection_justification.md # report (auto-generated by feature_importance)```**Logs (when present):**```logs/βββ face_orientation_training_log.jsonβββ mlp_face_orientation_training_log.jsonβββ xgboost_face_orientation_training_log.json```## 2. Log Format12 unmodified lines13141516171819202122232412 unmodified linesfeature_selection_justification.md # report (auto-generated by feature_importance)```**Logs (when present):** Scripts write to `evaluation/logs/`. MLP script: `face_orientation_training_log.json`; XGBoost script/notebook: `xgboost_face_orientation_training_log.json`; MLP notebook may write `mlp_face_orientation_training_log.json`.```logs/βββ face_orientation_training_log.json # from models/mlp/train.pyβββ xgboost_face_orientation_training_log.jsonβββ (optional) mlp_face_orientation_training_log.json # from notebooks/mlp.ipynb```## 2. Log Format
26 unmodified lines27282930313233343526 unmodified linesdef _resolve_xgb_path():p = os.path.join(_PROJECT_ROOT, "models", "xgboost", "checkpoints", "face_orientation_best.json")if os.path.isfile(p):return preturn os.path.join(_PROJECT_ROOT, "checkpoints", "xgboost_face_orientation_best.json")26 unmodified lines27282930313226 unmodified linesdef _resolve_xgb_path():return os.path.join(_PROJECT_ROOT, "checkpoints", "xgboost_face_orientation_best.json")
926 unmodified lines927928929930931932933926 unmodified lines}if combiner_path:cfg["combiner"] = "logistic"cfg["combiner_path"] = os.path.normpath(combiner_path)with open(config_path, "w", encoding="utf-8") as f:json.dump(cfg, f, indent=2)print(f" Written {config_path} (use_xgb={cfg['use_xgb']}, combiner={cfg.get('combiner', 'heuristic')})")926 unmodified lines927928929930931932933926 unmodified lines}if combiner_path:cfg["combiner"] = "logistic"cfg["combiner_path"] = os.path.basename(combiner_path)with open(config_path, "w", encoding="utf-8") as f:json.dump(cfg, f, indent=2)print(f" Written {config_path} (use_xgb={cfg['use_xgb']}, combiner={cfg.get('combiner', 'heuristic')})")
63 unmodified lines64656667686970235 unmodified lines30630730830931031131263 unmodified lines" \"reg_alpha\": 1.1407,\n"," \"reg_lambda\": 2.4181,\n"," \"eval_metric\": \"logloss\",\n"," \"checkpoints_dir\": os.path.join(PROJECT_ROOT, \"models\", \"xgboost\", \"checkpoints\"),\n"," \"logs_dir\": os.path.join(PROJECT_ROOT, \"evaluation\", \"logs\"),\n","}\n","\n",235 unmodified lines"outputs": [],"source": ["os.makedirs(CFG[\"checkpoints_dir\"], exist_ok=True)\n","model_path = os.path.join(CFG[\"checkpoints_dir\"], f\"{CFG['model_name']}_best.json\")\n","model.save_model(model_path)\n","\n","history = {\n",63 unmodified lines64656667686970235 unmodified lines30630730830931031131263 unmodified lines" \"reg_alpha\": 1.1407,\n"," \"reg_lambda\": 2.4181,\n"," \"eval_metric\": \"logloss\",\n"," \"checkpoints_dir\": os.path.join(PROJECT_ROOT, \"checkpoints\"),\n"," \"logs_dir\": os.path.join(PROJECT_ROOT, \"evaluation\", \"logs\"),\n","}\n","\n",235 unmodified lines"outputs": [],"source": ["os.makedirs(CFG[\"checkpoints_dir\"], exist_ok=True)\n","model_path = os.path.join(CFG[\"checkpoints_dir\"], f\"xgboost_{CFG['model_name']}_best.json\")\n","model.save_model(model_path)\n","\n","history = {\n",
14 unmodified lines1516171819202114 unmodified lines|----------|----------|-------|--------|| `FaceMeshPipeline` | Head pose + eye geometry | Rule-based fusion | `models/head_pose.py`, `models/eye_scorer.py` || `MLPPipeline` | 10 selected features | PyTorch MLP (10β64β32β2) | `checkpoints/mlp_best.pt` + `scaler_mlp.joblib` || `XGBoostPipeline` | 10 selected features | XGBoost | `models/xgboost/checkpoints/face_orientation_best.json` |## 3. Running14 unmodified lines1516171819202114 unmodified lines|----------|----------|-------|--------|| `FaceMeshPipeline` | Head pose + eye geometry | Rule-based fusion | `models/head_pose.py`, `models/eye_scorer.py` || `MLPPipeline` | 10 selected features | PyTorch MLP (10β64β32β2) | `checkpoints/mlp_best.pt` + `scaler_mlp.joblib` || `XGBoostPipeline` | 10 selected features | XGBoost | `checkpoints/xgboost_face_orientation_best.json` |## 3. Running
328 unmodified lines32933033133233333433533633766 unmodified lines404405406407408409410411412169 unmodified lines582583584585586587588589590591328 unmodified linesclass MLPPipeline:def __init__(self, model_dir=None, detector=None, threshold=0.23):if model_dir is None:model_dir = os.path.join(_PROJECT_ROOT, "MLP", "models")if not os.path.exists(model_dir):model_dir = os.path.join(_PROJECT_ROOT, "checkpoints")self._mlp, self._scaler, self._feature_names = _load_mlp_artifacts(model_dir)self._indices = [FEATURE_NAMES.index(n) for n in self._feature_names]66 unmodified linesdef _resolve_xgb_path():p = os.path.join(_PROJECT_ROOT, "models", "xgboost", "checkpoints", "face_orientation_best.json")if os.path.isfile(p):return preturn os.path.join(_PROJECT_ROOT, "checkpoints", "xgboost_face_orientation_best.json")169 unmodified linesfrom xgboost import XGBClassifierif model_path is None:model_path = os.path.join(_PROJECT_ROOT, "models", "xgboost", "checkpoints", "face_orientation_best.json")if not os.path.isfile(model_path):# Fallback to legacy pathmodel_path = os.path.join(_PROJECT_ROOT, "checkpoints", "xgboost_face_orientation_best.json")if not os.path.isfile(model_path):raise FileNotFoundError(f"No XGBoost checkpoint at {model_path}")328 unmodified lines32933033133233333433566 unmodified lines402403404405406407169 unmodified lines577578579580581582583328 unmodified linesclass MLPPipeline:def __init__(self, model_dir=None, detector=None, threshold=0.23):if model_dir is None:model_dir = os.path.join(_PROJECT_ROOT, "checkpoints")self._mlp, self._scaler, self._feature_names = _load_mlp_artifacts(model_dir)self._indices = [FEATURE_NAMES.index(n) for n in self._feature_names]66 unmodified linesdef _resolve_xgb_path():return os.path.join(_PROJECT_ROOT, "checkpoints", "xgboost_face_orientation_best.json")169 unmodified linesfrom xgboost import XGBClassifierif model_path is None:model_path = os.path.join(_PROJECT_ROOT, "checkpoints", "xgboost_face_orientation_best.json")if not os.path.isfile(model_path):raise FileNotFoundError(f"No XGBoost checkpoint at {model_path}")
README.md+1-1
evaluation/README.md+4-4
evaluation/feature_importance.py-3
evaluation/justify_thresholds.py+1-1
notebooks/xgboost.ipynb+2-2
ui/README.md+1-1
ui/pipeline.py+2-10