Instructions to use haresh2792005/MFAF-Net with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MediaPipe
How to use haresh2792005/MFAF-Net with MediaPipe:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download mfaf_net/module2_patient_analysis.py from haresh2792005/MFAF-Net: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/haresh2792005/MFAF-Net/resolve/main/mfaf_net/module2_patient_analysis.py
- Command line
-
hf download hf://haresh2792005/MFAF-Net/mfaf_net/module2_patient_analysis.py
-
curl -L -o module2_patient_analysis.py https://huggingface.co/haresh2792005/MFAF-Net/resolve/main/mfaf_net/module2_patient_analysis.py
3.05 kB
| """ | |
| Module 2 β Patient Information Analysis. | |
| Encodes patient demographics and procedure information into a fixed-length | |
| feature vector used for downstream feature fusion. | |
| """ | |
| import numpy as np | |
| PROCEDURES = [ | |
| 'rhinoplasty', | |
| 'blepharoplasty', | |
| 'rhytidectomy', | |
| 'genioplasty', | |
| 'forehead_surgery', | |
| 'brow_lift', | |
| ] | |
| FITZPATRICK_MAP = { | |
| 'I': 0.0, '1': 0.0, 'TYPE I': 0.0, | |
| 'II': 0.2, '2': 0.2, 'TYPE II': 0.2, | |
| 'III': 0.4, '3': 0.4, 'TYPE III': 0.4, | |
| 'IV': 0.6, '4': 0.6, 'TYPE IV': 0.6, | |
| 'V': 0.8, '5': 0.8, 'TYPE V': 0.8, | |
| 'VI': 1.0, '6': 1.0, 'TYPE VI': 1.0, | |
| } | |
| SEX_MAP = { | |
| 'm': 0.0, | |
| 'male': 0.0, | |
| 'f': 1.0, | |
| 'female': 1.0, | |
| 'other': 0.5, | |
| } | |
| def analyze_patient( | |
| age: str, | |
| sex: str, | |
| skin_type: str, | |
| procedure: str, | |
| treatment_history: str, | |
| ) -> dict: | |
| """ | |
| Encode patient information into a numerical feature vector. | |
| Feature vector layout (12 elements): | |
| [0] β age normalised (age / 100) | |
| [1] β sex encoding (M=0.0, F=1.0, Other=0.5) | |
| [2] β skin type Fitzpatrick (I=0.0 β¦ VI=1.0) | |
| [3β8] β procedure one-hot (6 dims) | |
| [9] β treatment_history (0 or 1) | |
| [10β11] β reserved zeros (padding to reach 12) | |
| Parameters | |
| ---------- | |
| age : str Patient age as string integer. | |
| sex : str 'M', 'Male', 'F', 'Female', or 'Other'. | |
| skin_type : str Fitzpatrick type IβVI. | |
| procedure : str One of the six supported procedure ids. | |
| treatment_history : str '0' or '1'. | |
| Returns | |
| ------- | |
| dict with keys: | |
| feature_vector β np.ndarray of shape (12,), dtype float32 | |
| summary β human-readable dict of encoded values | |
| """ | |
| # --- Age --- | |
| try: | |
| age_val = max(0.0, min(1.0, float(age) / 100.0)) | |
| except (ValueError, TypeError): | |
| age_val = 0.3 | |
| # --- Sex --- | |
| sex_key = str(sex).strip().lower() if sex is not None else 'other' | |
| sex_val = SEX_MAP.get(sex_key, 0.5) | |
| # --- Skin type --- | |
| skin_key = str(skin_type).strip().upper() if skin_type is not None else 'III' | |
| skin_val = FITZPATRICK_MAP.get(skin_key, 0.4) | |
| # --- Procedure one-hot (6 dims) --- | |
| proc_onehot = [0.0] * len(PROCEDURES) | |
| if procedure in PROCEDURES: | |
| proc_onehot[PROCEDURES.index(procedure)] = 1.0 | |
| # --- Treatment history --- | |
| try: | |
| tx_val = float(int(treatment_history)) | |
| except (ValueError, TypeError): | |
| tx_val = 0.0 | |
| tx_val = max(0.0, min(1.0, tx_val)) | |
| # Assemble vector | |
| vector = [age_val, sex_val, skin_val] + proc_onehot + [tx_val, 0.0, 0.0] | |
| feature_vector = np.array(vector, dtype=np.float32) | |
| summary = { | |
| 'age_encoded': round(age_val, 4), | |
| 'sex_encoded': sex_val, | |
| 'skin_type_encoded': skin_val, | |
| 'procedure': procedure, | |
| 'procedure_onehot': proc_onehot, | |
| 'treatment_history': tx_val, | |
| } | |
| return { | |
| 'feature_vector': feature_vector, | |
| 'summary': summary, | |
| } | |