Skip to content

Latest commit

 

History

54 Commits

Folders and files

Repository files navigation

SatQuery-AI

Ask questions about satellite images in plain language. SatQuery-AI is a multi-modal remote-sensing analysis platform: upload an optical or SAR scene (PNG, JPEG, TIFF or GeoTIFF), ask a question, and an agentic FastAPI backend routes it to the right pipeline: visual question answering, change detection, optical–SAR fusion or a feature scan. Every run returns an answer, a confidence signal, an evidence image, a full execution trace and a downloadable PDF report.

Built on Qwen2-VL-2B-Instruct with task-specific LoRA adapters, a React + Vite dashboard, and a geospatial preprocessing layer for real GeoTIFF data.


Features

Capability What it does
Visual Q&A Ask open questions ("Describe this scene") or closed ones ("Is there a river?", "Is this rural or urban?") about a single image. Closed questions use a fine-tuned remote-sensing VQA adapter.
Change detection Upload a before and after image of the same modality. The images are aligned, ordered by acquisition date when metadata is available, and compared with pixel and colour-difference analysis. Changed regions are boxed on an evidence image and described by the model.
Optical–SAR fusion Upload one optical and one SAR image. They are fused with an HSV brightness blend (colour and detail from optical, brightness modulated by smoothed SAR backscatter) and the composite is analysed.
Feature scans Tile-based grid scans for mining, deforestation and agriculture, each with its own LoRA adapter. Returns a headline, confidence level, numbered findings with boxes, and a 4×4 score grid.
Clarification Ambiguous queries get a follow-up question instead of a guess.
Audit trace Each response includes the task chosen, routing decision, pipeline stages and warnings.
PDF reports Every run produces a PDF report that can be rebuilt with the full conversation.
Accounts Email sign-up with OTP verification, Google sign-in, and per-account report history.

How a request is routed

                     ┌──────────────┐
  query + 0-2 images │  /analyze    │
 ───────────────────▶│  (FastAPI)   │
                     └──────┬───────┘
                            │ preprocessing: load, standardise, validate, align GeoTIFFs
                            ▼
        ┌───────────────────┼─────────────────────┬──────────────────────┐
   1 image, general    1 image + adapter     2 images, same         2 images, different
        │                   │                modality               modality
        ▼                   ▼                    ▼                      ▼
   Visual Q&A         Feature grid scan    Change detection      Optical–SAR fusion
 (Qwen2-VL + VQA      (mining / defor- /   (alignment, diff        (HSV blend, then
  adapter for closed    agriculture LoRA)    regions, captions)      model analysis)
  questions)
        └───────────────────┴──────────┬──────────┴──────────────────────┘
                                       ▼
                answer + confidence + evidence image + trace + PDF report

Tech stack

  • Model: Qwen2-VL-2B-Instruct (4-bit, via bitsandbytes) with PEFT LoRA adapters
  • Backend: Python, FastAPI, Uvicorn, PyTorch, Transformers, PEFT, OpenCV, Rasterio, ReportLab, SQLite (accounts)
  • Frontend: React 19, Vite, Tailwind CSS, React Router, Leaflet / React-Leaflet, Google Maps JS API
  • CI: GitHub Actions (backend pytest + frontend tests and lint)
  • Deployment: frontend on Vercel, backend served from a GPU machine through an ngrok tunnel

Project structure

SatQuery-AI/
├── backend/
│   ├── main_api.py                   # FastAPI app: /analyze, /preview, /report, /health
│   ├── auth.py                       # Sign-up/OTP, login, Google sign-in, report history
│   ├── cli.py                        # Terminal client for a running backend
│   ├── run_eval.py                   # Benchmark evaluation entry point
│   ├── pdf_report_generator.py
│   ├── agent_manager/                # Agent controller, prompts, routing, grid scans, clarification
│   ├── change_detection/             # Change-detection engine and change reports
│   ├── fusion/                       # Optical–SAR fusion
│   ├── geospatial_preprocessing/     # GeoTIFF loading, SAR preprocessing, alignment, dates
│   ├── evaluation/                   # Benchmarks, metrics, answer spaces, runner
│   ├── training/                     # QLoRA training scripts for the VQA adapter
│   ├── models/adapters/              # vqa, mining, deforestation, agriculture LoRA adapters
│   └── tests/                        # pytest suite (no GPU needed)
├── frontend/
│   └── src/
│       ├── landing/                  # Landing page
│       ├── auth/                     # Sign-in / sign-up pages
│       └── dashboard/                # Imagery, Change, Fusion, Scans, Assistant and Report panels
├── requirements.txt
├── start-online.ps1                  # Starts backend + ngrok tunnel (Windows)
└── LICENSE

Getting started

Prerequisites

  • Python 3.10+ (CI uses 3.12)
  • Node.js 22+
  • An NVIDIA GPU with about 5 GB of free VRAM for the model (tested on an RTX 3050 6 GB laptop GPU)

1. Backend

cd backend
python -m venv .venv
source .venv/bin/activate            # Windows: .venv\Scripts\activate

pip install -r ../requirements.txt
pip install fastapi "uvicorn[standard]" python-multipart peft bitsandbytes reportlab pypdf scipy httpx psutil

cp .env.example .env                 # then fill in the values (see below)
python -m uvicorn main_api:app --host 127.0.0.1 --port 8000

The model takes about a minute to load. Check http://127.0.0.1:8000/health to confirm it is ready, and http://127.0.0.1:8000/docs for the interactive API docs.

2. Frontend

cd frontend
npm install
cp .env.example .env                 # set VITE_BACKEND_URL=http://127.0.0.1:8000
npm run dev

Open http://localhost:5173.

3. Putting it online (optional, Windows)

start-online.ps1 starts the backend and an ngrok tunnel in separate windows so a Vercel-hosted frontend can reach the backend on your machine:

.\start-online.ps1 -Domain your-subdomain.ngrok-free.dev

Set CORS_ORIGINS in backend/.env to your Vercel URL, and VITE_BACKEND_URL in Vercel's environment variables to the ngrok address.

Configuration

backend/.env

Variable Purpose
CORS_ORIGINS Comma-separated frontend origins allowed to call the API
REQUIRE_SIGN_IN 1 requires sign-in on /analyze, /preview and /report; 0 for local development only
SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_FROM, SMTP_USE_TLS Email delivery for sign-up verification codes
GOOGLE_CLIENT_ID OAuth client ID for "Continue with Google"
REPORT_RETENTION_HOURS Delete report folders older than this (unset = keep forever)

Optional tuning: SATQUERY_MAX_PIXELS (image detail vs. VRAM), SAR_FUSION_WEIGHT (0–1, how strongly SAR affects fused brightness), MAX_UPLOAD_MB, GRID_YES_THRESHOLD.

frontend/.env

Variable Purpose
VITE_BACKEND_URL Backend base URL, no trailing slash
VITE_GOOGLE_MAPS_API_KEY Google Maps key for the landing page globe (restrict it to your domain)

Vite bakes these into the built JavaScript, so never put a secret in the frontend .env.

API

Method Endpoint Description
POST /analyze Query plus up to 2 images (query, adapter, modality_a, modality_b, chat_history, images)
POST /preview Browser-safe PNG preview of an uploaded TIFF/GeoTIFF
POST /report Rebuild a run's PDF with the full conversation
GET /health Backend and model status
POST /auth/signup, /auth/verify-signup, /auth/resend-otp Email sign-up with OTP
POST /auth/login, /auth/google, /auth/logout Sessions
GET /auth/me, /auth/reports, /auth/config Current user, report history, sign-in config

CLI

With the backend running, try queries from a terminal:

cd backend
python cli.py --image scene.png --query "What is here?"
python cli.py --image before.tif --image2 after.tif --modality sar         # change detection
python cli.py --image optical.png --image2 sar.png --modality2 sar          # fusion
python cli.py --image scene.png --adapter mining                           # feature scan

Models and evaluation

All adapters are LoRA adapters on Qwen2-VL-2B-Instruct.

Adapter Training data Task
vqa RSVQA-LR train split (57,223 questions, 572 Sentinel-2 tiles), QLoRA, 1 epoch Closed remote-sensing questions
mining BigEarthNet (Sentinel-2) subset, ~14,000 samples Yes/no feature presence
deforestation BigEarthNet (Sentinel-2) subset, ~14,000 samples Yes/no feature presence
agriculture BigEarthNet (Sentinel-2) subset, ~14,000 samples Yes/no feature presence

VQA adapter on RSVQA-LR test (1,000 stratified questions, seed 0):

Accuracy
Base model 58.4%
Answer-prior floor 68.9%
SatQuery-AI vqa adapter 89.9% (95% CI 87.5–91.9)

Per type: presence 91.5%, comparison 88.5%, rural/urban 10/10. Expected calibration error dropped from 0.245 to 0.139. Counting is not solved (24.7%, at the floor).

Run the evaluation yourself on RSVQA-LR, RSVQA-HR, CDVQA or VRSBench-VQA:

cd backend
python run_eval.py rsvqa-lr --root /path/to/RSVQA_LR --limit 500
python run_eval.py rsvqa-lr --root /path/to/RSVQA_LR --limit 500 --predictor prior   # no-GPU baseline

Results are written to eval_results/, and re-running the same command resumes.

Testing

The backend tests stub out torch, transformers, PEFT and the model, so no GPU or weights are needed:

cd backend
pip install pytest pypdf rasterio reportlab opencv-python-headless scipy fastapi httpx python-multipart pillow numpy python-dotenv
python -m pytest tests -q

cd ../frontend
npm test
npm run lint

Limitations

  • The VQA adapter is trained on 10 m Sentinel-2 RGB only. It has not been validated on sub-metre imagery, SAR or Cartosat data, and is never used for SAR.
  • RSVQA labels come from OpenStreetMap and inherit its gaps.
  • Object counts are unreliable.
  • Several change-detection and fusion thresholds are starting values, not tuned against labelled data.
  • Model output can be wrong; treat answers as decision support, not ground truth.

License

Released under the MIT License.

Releases

Packages

Contributors

Languages