This guide details how to install, set up, and configure the Selfie Rectification pipeline on Windows and macOS.
- Operating System: Windows 10 or 11 (64-bit)
- Python: Python 3.10 (3.10.11 recommended)
- NVIDIA GPU: Required for hardware acceleration (e.g., RTX 30-series/40-series with CUDA support, RTX 3050 Laptop 6GB tested).
- Disk Space: ~15 GB (for deep learning model weights, dependencies, and datasets)
- Git: Installed and added to system
PATH.
- Operating System: macOS 12 Monterey or later
- Python: Python 3.10 or 3.11
- Hardware: Apple Silicon (M1/M2/M3 recommended) for Metal Performance Shaders (MPS) hardware acceleration, or Intel CPU.
- Disk Space: ~10 GB.
- Git: Xcode Command Line Tools installed (
xcode-select --install).
First, clone the repository (if you haven't already):
git clone https://github.com/YTFL/UnDistort-Selfie.git
cd UnDistort-SelfieAll commands below assume you are inside the SelfieRectification/ sub-directory.
Open a PowerShell terminal as a regular user:
# Move to the source folder
cd SelfieRectification
# Create a virtual environment
python -m venv .venv
# Activate the virtual environment
.\.venv\Scripts\Activate.ps1
# Upgrade pip package manager
python -m pip install --upgrade pip
# Install PyTorch with CUDA 11.8 support
python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# Install remaining pipeline dependencies
python -m pip install -r requirements.txtOpen a standard Terminal:
# Move to the source folder
cd SelfieRectification
# Create a virtual environment
python3 -m venv .venv
# Activate the virtual environment
source .venv/bin/activate
# Upgrade pip package manager
python3 -m pip install --upgrade pip
# Install PyTorch for macOS
python3 -m pip install torch torchvision torchaudio
# Install remaining macOS dependencies
python3 -m pip install -r requirements-mac.txtOn first execution, the pipeline automatically warms its cache by downloading:
- Depth Anything V2 Small: Automatically downloaded to
cache/via HuggingFace Hub. - InsightFace (buffalo_sc): Automatically downloaded to your user directory (
~/.insightface/).
However, if you wish to pre-download all weights to avoid runtime downloads, run:
python -m scripts.download_weightsTo stream and pre-cache benchmark images from FFHQ and CelebA-HQ academic datasets:
python -m scripts.download_datasetsVerify that your Python, CUDA, PyTorch, and third-party dependencies are properly configured:
# Check library paths and hardware devices
python -m scripts.verify_setup
# Test CUDA tensor allocation and speed
python -m scripts.test_gpu============================================================
SETUP VERIFICATION
============================================================
PyTorch version: 2.2.2+cu118
CUDA available: True
GPU: NVIDIA GeForce RTX 3050 6GB Laptop GPU
Device: cuda
[OK] MediaPipe installed
[OK] OpenCV installed
[OK] Transformers installed
[OK] Diffusers installed
[OK] Gradio installed
Repository status:
[OK] mediapipe
[OK] Depth-Anything-V2
...
============================================================
The Gradio Web UI provides a slide-to-compare interface, diagnostic meshes, vector outputs, and sliders to control lens setback parameters.
- Windows:
Simply double-click launch.bat or execute:
.\.venv\Scripts\Activate.ps1 .\launch.bat - macOS:
source .venv/bin/activate python -m scripts.gradio_app
Open http://localhost:7860 in your browser.
To run the pipeline on an image and generate evaluation metrics:
# Activate virtual environment
source .venv/bin/activate # macOS
.\.venv\Scripts\Activate.ps1 # Windows
# Run pipeline
python -m scripts.main <path_to_selfie>Output files will be saved under outputs/<timestamp>/, along with a base64-embedded interactive HTML report saved under outputs/reports/.
This occurs due to a known packaging bug in basicsr. The setup script should resolve this automatically, but if it persists, execute:
python -m scripts.verify_setupThis programmatically creates the missing version.py file inside your virtual environment libraries.
If you run out of GPU memory during Stable Diffusion img2img texture refinement:
- The pipeline runs with Stable Diffusion disabled by default. If you enable it, use the
--no-diffusionor Gradio toggles. - Reduce input image resolution (tested up to 1024x1024 on 6GB VRAM).
- Check that PyTorch is using
fp16half-precision (default).
If you receive crash logs printing UnicodeEncodeError when trying to print emojis or UTF-8 characters:
- Standard Windows console encoding defaults to
CP1252. - We have replaced all decorative console emojis with ASCII prefixes (
[OK],[WARN],[INFO],[ERROR]). - Run
chcp 65001in CMD before running the python script to force UTF-8 support.
- Ensure you have installed native ARM64 Python, not Intel Python via Rosetta 2.
- The pipeline automatically falls back to CPU-only execution for libraries that do not fully support MPS (e.g. MediaPipe). PyTorch tensor calculations will leverage MPS.