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 CONFERENCE_PAPER_MFAF_NET.md from haresh2792005/MFAF-Net: direct link, hf CLI and curl.
- Browser
- Download file 13.1 kB
-
https://huggingface.co/haresh2792005/MFAF-Net/resolve/main/CONFERENCE_PAPER_MFAF_NET.md
- Command line
-
hf download hf://haresh2792005/MFAF-Net/CONFERENCE_PAPER_MFAF_NET.md
-
curl -L -o CONFERENCE_PAPER_MFAF_NET.md https://huggingface.co/haresh2792005/MFAF-Net/resolve/main/CONFERENCE_PAPER_MFAF_NET.md
13.1 kB
| # MFAF-Net: A Multimodal Facial Analysis and Feature-Guided Network for Cosmetic Surgery Outcome Simulation | |
| > **Document Purpose:** Structured IEEE/conference paper draft aligned directly with the implemented MFAF-Net codebase (`app.py`, `mfaf_net/*`, `train_mfaf_net.py`, and `generate_paper_figures.py`). Experimental metric placeholders marked `[INSERT_FROM_TRAINING_LOG]` must be populated after running `python train_mfaf_net.py` locally. | |
| --- | |
| ## Abstract | |
| Pre-operative expectation management is a critical factor in facial cosmetic surgery, where misalignment between a patient's visual expectations and realistic post-operative outcomes frequently leads to dissatisfaction or revision procedures. Existing visual simulation tools either rely on simple manual image warping or heavy diffusion-based pipelines (such as LandmarkDiff) that operate solely on a 2D photograph without incorporating patient demographic context or outputting standardized quantitative evaluations. In this paper, we propose **MFAF-Net (Multimodal Facial Analysis and Feature-guided Network)**, an interpretable, lightweight, five-module framework for procedure-aware cosmetic facial simulation. MFAF-Net extracts 468 canonical facial landmarks and anthropometric distances via MediaPipe FaceMesh (Module 1), encodes patient metadata—including age, biological sex, Fitzpatrick skin phototype, target procedure, and prior treatment history—into a 12-dimensional demographic vector (Module 2), and integrates both modalities through procedure-aware regional attention fusion (Module 3). A dual-head neural predictor and Delaunay-triangulated piecewise affine warping engine then synthesize the simulated post-operative face locally on CPU hardware (Module 4), followed by difference-heatmap generation and quantitative evaluation via SSIM, PSNR, MAE, and changed-pixel percentage (Module 5). Evaluated as a proof-of-concept on the Complete Plastic Surgery Dataset (1,274 facial images across five surgical categories), MFAF-Net demonstrates an explainable, accessible, and reproducible educational framework for facial aesthetic simulation. | |
| **Keywords:** *Multimodal Deep Learning, Facial Landmark Mesh, Cosmetic Surgery Simulation, Procedure-Aware Attention, Piecewise Affine Warping, Quantitative Image Evaluation* | |
| --- | |
| ## 1. Introduction | |
| Elective facial aesthetic procedures—including rhinoplasty, blepharoplasty, rhytidectomy, genioplasty, forehead contouring, and brow lifting—require clear communication between clinicians and patients regarding realistic anatomical changes. Conventional 2D morphing software depends on manual slider manipulation, while recent generative diffusion frameworks such as **LandmarkDiff** (ControlNet + Stable Diffusion 1.5) require GPU-accelerated cloud/Docker infrastructure and condition solely on a single image. | |
| To address these gaps, this work introduces **MFAF-Net** with three core research contributions: | |
| 1. **Multimodal Patient Conditioning:** Jointly fuses facial geometry with patient-specific clinical attributes (age, sex, Fitzpatrick skin type I–VI, and prior cosmetic treatment history). | |
| 2. **Procedure-Aware Landmark Attention Fusion:** Dynamically amplifies attention weights ($\times 3.0$ prior) over anatomical zones relevant to the selected surgery while anchoring non-target facial identity regions. | |
| 3. **Difference-Map & Quantitative Evaluation Pipeline:** Produces an interpretable JET-colormap pixel-difference map alongside standardized quality metrics (SSIM, PSNR, MAE, and changed-pixel area percentage). | |
| *Disclaimer: MFAF-Net is designed exclusively as an educational and academic visual simulation prototype and does not provide clinical predictions or medical advice.* | |
| --- | |
| ## 2. Comparison with Existing Approaches | |
| | Feature | LandmarkDiff (Existing Baseline) | MFAF-Net (Proposed Framework) | | |
| | :--- | :--- | :--- | | |
| | **Input Modality** | Single 2D image only | Multimodal (Image + Age + Sex + Skin Type + History) | | |
| | **Landmark Extraction** | 478-point 3D mesh | 468-point MediaPipe FaceMesh + 8 anthropometric ratios | | |
| | **Patient Context** | None | 12-dimensional normalized clinical feature vector | | |
| | **Spatial Focus** | Fixed Gaussian RBF radii (~15–30 px) | Learnable procedure-to-region attention + piecewise affine warp | | |
| | **Visual Explainability** | Simulated image only | Simulated image + annotated mesh + JET difference heatmap | | |
| | **Evaluation Metrics** | Qualitative / visual review | SSIM, PSNR, MAE, and changed-pixel percentage | | |
| | **Compute Requirement** | GPU + Stable Diffusion 1.5 (~multi-GB) | CPU-compatible lightweight Flask & PyTorch (~20 MB MediaPipe) | | |
| --- | |
| ## 3. Proposed Architecture: MFAF-Net | |
| ### 3.1 System Block Diagram | |
| ```mermaid | |
| flowchart TD | |
| IMG["Input Facial Image I"] --> M1["Module 1: Facial Feature Extraction\nMediaPipe FaceMesh (468 pts) + 8 Anthropometrics"] | |
| META["Patient Metadata\n(Age, Sex, Fitzpatrick I-VI, Procedure, History)"] --> M2["Module 2: Patient Analysis\n12-Dim Encoded Feature Vector P"] | |
| M1 --> M3["Module 3: Procedure-Aware Feature Fusion\nRegion Attention Weights + Fused Vector"] | |
| M2 --> M3 | |
| M3 --> M4["Module 4: Facial Simulation\nMFAFNetModel Residual Delta + Delaunay Piecewise Affine Warp"] | |
| IMG --> M4 | |
| M4 --> SIM["Simulated Output Image I_sim"] | |
| IMG --> M5["Module 5: Result Comparison\nJET Difference Heatmap + SSIM, PSNR, MAE, Changed %"] | |
| SIM --> M5 | |
| ``` | |
| --- | |
| ### 3.2 Mathematical Formulation | |
| #### Module 1 — Facial Feature Extraction | |
| Given an input facial image $I \in \mathbb{R}^{H \times W \times 3}$, MediaPipe FaceMesh extracts $N = 468$ pixel-space landmarks: | |
| $$L = \{(x_i, y_i)\}_{i=1}^{468}, \quad x_i \in [0, W), \; y_i \in [0, H)$$ | |
| Normalized landmark coordinates are obtained as $L_{\text{norm}, i} = (x_i / W, \; y_i / H)$. Eight scalar Euclidean anthropometric measurements $M \in \mathbb{R}^8$ are computed between canonical landmark pairs $(a, b)$: | |
| $$d(a, b) = \| L_a - L_b \|_2$$ | |
| covering `nose_width`, `nose_length`, `left_eye_width`, `right_eye_width`, `eye_width`, `face_width`, `jaw_width`, and `chin_projection`. | |
| #### Module 2 — Patient Information Analysis | |
| Structured patient inputs are encoded into a fixed 12-dimensional vector $P \in \mathbb{R}^{12}$: | |
| $$P = \big[\tilde{a}, \; s, \; f, \; \mathbf{e}_{\text{proc}} \in \{0,1\}^6, \; h_{\text{tx}}, \; 0, \; 0\big]$$ | |
| where $\tilde{a} = \text{clip}(\text{age}/100, 0, 1)$, $s \in \{0.0, 0.5, 1.0\}$ encodes sex ($\text{Male}=0.0, \text{Other}=0.5, \text{Female}=1.0$), $f \in \{0.0, 0.2, 0.4, 0.6, 0.8, 1.0\}$ encodes Fitzpatrick phototypes I–VI, $\mathbf{e}_{\text{proc}}$ is the 6-class one-hot surgical procedure vector, and $h_{\text{tx}} \in \{0, 1\}$ denotes prior cosmetic treatment history. | |
| #### Module 3 — Procedure-Aware Feature Fusion | |
| Let $\mathcal{R} = \{\text{nose}, \text{eyes}, \text{eyebrows}, \text{chin}, \text{jawline}, \text{forehead}\}$ denote six anatomical regions represented by a binary incidence matrix $R \in \{0, 1\}^{6 \times 468}$. Given procedure $p \in \{1, \dots, 6\}$, region attention weights $\alpha_p \in \mathbb{R}^6$ assign $\alpha_{p,r} = 3.0$ to the primary surgical target region, $1.5$ to adjacent regions, and $1.0$ elsewhere. Per-landmark weights $w_i = \max_{r : R_{r,i}=1} \alpha_{p,r}$ scale the flattened coordinates, and min-max normalization yields: | |
| $$F_{\text{fused}} = \left[ \frac{L_{\text{flat}} \odot \mathbf{w}}{\max(L_{\text{flat}} \odot \mathbf{w})} \;\Big\|\; \frac{M}{\max(M)} \;\Big\|\; P \right]$$ | |
| #### Module 4 — Neural Displacement & Piecewise Affine Simulation | |
| In the trainable `MFAFNetModel`, learnable procedure-to-region weights $A \in \mathbb{R}^{6 \times 6}$ (initialized from clinical priors $\alpha$) generate per-landmark attention weights $\mathbf{w}_p = \max(\text{ReLU}(A_p) + 0.5, 1.0) \cdot R$. A multi-layer perceptron fusion encoder maps $[L_{\text{norm}} \odot \mathbf{w}_p \;\|\; M_{\text{norm}} \;\|\; P \;\|\; A_p]$ into a latent vector $\mathbf{z} \in \mathbb{R}^{128}$, feeding two heads: | |
| $$\Delta \hat{L} = \delta_{\max} \cdot \tanh\big(\phi_{\text{disp}}(\mathbf{z})\big) \odot \frac{\mathbf{w}_p}{\max(\mathbf{w}_p)}, \qquad \hat{y}_{\text{proc}} = \phi_{\text{cls}}(\mathbf{z})$$ | |
| with $\delta_{\max} = 0.08$. The model is trained jointly with Smooth-L1 displacement loss and Cross-Entropy procedure classification loss: | |
| $$\mathcal{L} = 100 \cdot \mathcal{L}_{\text{SmoothL1}}(\Delta \hat{L}, \Delta L_{\text{gt}}) + 0.5 \cdot \mathcal{L}_{\text{CE}}(\hat{y}_{\text{proc}}, y_{\text{proc}})$$ | |
| Destination landmarks $L_{\text{dst}} = L + \Delta \hat{L} \cdot [W, H]$ drive Delaunay triangulation over $L$ and per-triangle inverse affine warping (`cv2.warpAffine`), followed by linear blending ($0.85 \cdot I_{\text{warp}} + 0.15 \cdot I$) and Gaussian seam smoothing ($\sigma = 1.0$). | |
| #### Module 5 — Difference Mapping & Evaluation Metrics | |
| Given original image $I$ and simulated image $I_{\text{sim}}$: | |
| 1. **Difference Heatmap:** $D = |I - I_{\text{sim}}|$, mapped to RGB via `cv2.COLORMAP_JET`. | |
| 2. **Changed-Pixel Percentage:** $\text{CP}\% = \frac{100}{H W} \sum_{u,v} \mathbb{I}\!\left(\max_{c \in \{R,G,B\}} D_{u,v,c} > 15\right)$. | |
| 3. **Mean Absolute Error (MAE):** $\text{MAE} = \frac{1}{3 H W} \sum_{u,v,c} D_{u,v,c}$. | |
| 4. **Structural Similarity (SSIM) & PSNR:** Standard `skimage.metrics` evaluation over RGB channels with dynamic range $255$. | |
| --- | |
| ### 3.3 Algorithm 1: MFAF-Net Inference & Evaluation | |
| ```text | |
| Input: Facial photo I, patient metadata (age, sex, skin_type, procedure p, tx_history) | |
| Output: Annotated landmarks I_ann, simulated photo I_sim, diff map D_jet, metrics M | |
| 1. Extract 468 landmarks L and 8 measurements Meas from I using MediaPipe FaceMesh. | |
| 2. Encode metadata into 12-dim patient vector P via Module 2. | |
| 3. Compute procedure-aware region attention weights and fused vector F_fused via Module 3. | |
| 4. If trained checkpoint models/mfaf_net_best.pt is available: | |
| Predict normalized shifts delta_L using MFAFNetModel(L_norm, Meas_norm, P, p). | |
| L_dst <- clip(L + delta_L * [W, H]) | |
| Else: | |
| L_dst <- rule-based procedural shift scaled by age & treatment history. | |
| 5. Triangulate L via Delaunay subdivision; apply piecewise affine warp from L -> L_dst. | |
| 6. Blend warped image with I and apply Gaussian smoothing (sigma = 1.0) -> I_sim. | |
| 7. Compute D = |I - I_sim|, render JET heatmap D_jet, and compute SSIM, PSNR, MAE, CP%. | |
| 8. Return (I, I_ann, I_sim, D_jet, M). | |
| ``` | |
| --- | |
| ## 4. Dataset & Experimental Setup | |
| Experiments are structured around the **Complete Plastic Surgery Dataset** (`Complete_PlasticSurgery_Datasets`), comprising **1,274 facial images** organized into before/after pairs across five procedure directories: | |
| | Dataset Subfolder | Mapped MFAF-Net Procedure | Total Images | Usable Paired Cases | | |
| | :--- | :--- | :---: | :---: | | |
| | `Nose_Dataset` | Rhinoplasty | 348 | 174 | | |
| | `Eyelid_Dataset` | Blepharoplasty | 260 | 130 | | |
| | `Eyebrow_Dataset` | Brow Lift | 256 | 128 | | |
| | `FacialBones_Dataset` | Genioplasty / Facial Contour | 214 | 107 | | |
| | `Facelift_Dataset` | Rhytidectomy | 196 | 98 | | |
| | **Total** | **5 Active Categories** | **1,274** | **637** | | |
| ### Experimental Results (35 Epochs, 80/20 Train–Validation Split) | |
| - **Usable Face Pairs Extracted:** **637 / 637** (0 skipped; 100% trained on real Before → After landmark differences) | |
| - **Training Runtime:** **47.21 s** (CPU, batch size 16) | |
| - **Validation Loss Convergence:** Reduced from **1.44521** (Epoch 1) to **1.22404** (Best Validation Loss) | |
| - **Procedure Conditioning Consistency (Val):** **100.0%** *(auxiliary classification consistency with input procedure vector)* | |
| - **Validation Simulation vs. Pre-Op (`Before`, n=12):** SSIM = **0.7924**, PSNR = **17.01 dB**, MAE = **20.0231**, Changed Pixel Area = **36.14%** | |
| - **Validation Simulation vs. Ground-Truth Post-Op (`After`, n=12):** SSIM = **0.5204**, PSNR = **13.05 dB**, MAE = **41.4073** *(reflecting real-world lighting/pose/background shifts between independent clinical Before and After photos)* | |
| - **Generated Figures:** | |
| - `static/results/training_curves.png` (Loss & Accuracy convergence) | |
| - `static/results/paper_figures/paper_attention_matrix.png` (6×6 attention heatmap) | |
| - `static/results/paper_figures/paper_dataset_distribution.png` (Dataset distribution) | |
| - `static/results/paper_figures/paper_evaluation_summary.png` (Metric summary) | |
| --- | |
| ## 5. Limitations & Conclusion | |
| MFAF-Net bridges geometric interpretability and multimodal patient conditioning in a lightweight web architecture. Current limitations include: (1) geometric piecewise affine warping preserves original skin texture rather than synthesizing new lighting/shadows or scar healing textures as in latent diffusion models, and (2) the paired image dataset lacks per-patient demographic columns (`age`, `sex`, `skin_type`), requiring default values during benchmark training unless annotated externally. Future work will integrate conditional texture refinement conditioned on the predicted landmark displacements and clinically validated demographic cohorts. | |