- Python 3.9 or later
- Git
git clone <repository-url>
cd FR-IQA-Algopython3 -m venv venvActivate it:
- macOS / Linux:
source venv/bin/activate - Windows:
venv\Scripts\activate
Your prompt should now show (venv).
pip install --upgrade pip
pip install -r requirements.txt| Package | Purpose |
|---|---|
torch + torchvision |
VGG16 backbone, GPU-accelerated tensor ops |
numpy |
Array math and windowing functions |
scipy |
Cholesky decomposition, wavelet transforms |
scikit-image |
Multi-scale pyramid, Canny edge detector, morphological ops |
Pillow |
Image I/O (PNG, JPEG, TIFF …) |
opencv-python |
Convolutional filters, morphological dilation |
POT |
Sinkhorn–Knopp optimal transport (EMD approximation) |
colour-science |
sRGB → Oklab color space conversion |
The pipeline requires pre-trained VGG16 weights (~528 MB). Run the download script once:
python weights/download_vgg16.pyThe file is saved to weights/vgg16-397923af.pth. If the file already exists the script exits immediately.
The CLI currently supports PNG images only as input.
python upiqal_cli.py --reference ref.png --target tgt.png --output-dir results/| Flag | Description |
|---|---|
--reference |
Path to the reference (pristine) PNG image |
--target |
Path to the target (distorted) PNG image |
--output-dir |
Directory to save results (default: auto-generated with timestamp) |
--name |
Custom label for the auto-generated output directory name |
--max-side |
Maximum pixel dimension for the longer side (default: 512) |
The output directory will contain diagnostic heatmap PNGs and a report.json with the overall quality score and artifact breakdown.
Install uvicorn if not already included in your requirements:
pip install uvicornStart the server:
uvicorn main:app --app-dir web --reload --port 8000The API will be available at http://localhost:8000.
| Flag | Description |
|---|---|
main:app |
Module web/main.py, FastAPI instance named app |
--app-dir web |
Sets web/ as the working directory for the app |
--reload |
Auto-reloads on code changes (development only) |
--port 8000 |
Port to listen on |
Remove --reload in production.
deactivateModuleNotFoundError: No module named 'torch'
Make sure the virtual environment is active (source venv/bin/activate) before running any script.
colour package not found
Install it explicitly: pip install colour-science.
The inference stack (PyTorch + 528 MB VGG16 weights) is too large for Vercel's serverless Python runtime. The recommended topology:
- Vercel — serves the static frontend from
web/public/and a one-file proxyapi/proxy.pythat forwards/api/*requests upstream. - CPU host (Fly.io / Render / Railway) — runs the full FastAPI app from the top-level
Dockerfile.
brew install flyctl # or curl -L https://fly.io/install.sh | sh
fly auth login
fly launch --copy-config --name upiqal --no-deploy
fly deploy
# note the resulting URL, e.g. https://upiqal.fly.dev
curl https://upiqal.fly.dev/healthz # should return {"ok":true,"device":"cpu"}Adjust memory in fly.toml (default 2048 MB) if you see OOMs on large uploads.
Push to GitHub; create a new Web Service pointed at this repo. Render discovers render.yaml automatically. Keep the plan at Standard or higher (2 GB+) — Starter will OOM.
vercel login
vercel link
vercel env add BACKEND_URL production # paste https://upiqal.fly.dev
vercel --prodOpen the deployed URL. The analyzer calls /api/compare, which Vercel rewrites to /api/proxy, which forwards to ${BACKEND_URL}/api/compare.
On the backend host, set:
UPIQAL_ALLOWED_ORIGINS = https://your-vercel-domain.vercel.app
This restricts cross-origin POSTs to just your Vercel frontend.
# terminal 1 — backend
uvicorn web.main:app --host 127.0.0.1 --port 8000
# terminal 2 — vercel dev with the proxy pointed at the local backend
BACKEND_URL=http://127.0.0.1:8000 vercel devOpen the URL vercel dev prints and run an analysis; requests should traverse Vercel → api/proxy.py → local FastAPI.