Developer Quickstart
Get the Seg-Studio development environment running on Windows, macOS, or Linux/WSL.
Prerequisites
| Tool | Version | Notes |
|---|---|---|
| Python | 3.11+ | the lockfile is compiled for 3.11; 3.10 does not resolve it |
| Node.js | 18+ | Required for UI build and dev server |
| npm | 9+ | Bundled with Node.js |
| NVIDIA GPU (CUDA) | Optional | CUDA 12.8 (cu128); cu124 for older GPUs. Semantic training also runs on MPS or CPU (slower); object counting (instance) training needs CUDA. Annotation and inference work without one. |
| Apple Silicon | Optional | MPS acceleration on macOS (M1/M2/M3/M4) |
Verify prerequisites:
python --version # 3.11+
node --version # v18+
npm --version # 9+
nvidia-smi # optional — confirms CUDA driver
Project Structure
seg-studio/
apps/
trainer_api/ # FastAPI backend
serving_api/ # ONNX inference API
trainer_ui/ # React frontend
packages/
segcore/ # Training core (models, dataset, train loop)
seg-sdk/ # Python client SDK for the inference API
models/
sam_checkpoints/ # SAM model checkpoints
scripts/
windows/ # Windows setup/start scripts
macos/ # macOS setup/start scripts
Clone and Setup
1. Create a virtual environment
Windows:
cd seg-studio
python -m venv .venv-windows
.venv-windows\Scripts\activate
macOS:
cd seg-studio
python3 -m venv .venv-macos
source .venv-macos/bin/activate
Linux / WSL:
cd seg-studio
python3 -m venv .venv
source .venv/bin/activate
2. Install Python dependencies
pip install --no-deps -r apps/trainer_api/requirements.txt
pip install --no-deps -e packages/segcore
(--no-deps installs the lockfile as it is. It is a complete resolution;
resolved again, pip adds a second OpenCV build beside the pinned one.)
(segcore is the local training-core package; the editable install is the
documented path. If it is missing, the API falls back to a sys.path shim.)
For CUDA-enabled PyTorch on Windows with an NVIDIA GPU: the lockfile pins
torch 2.13.0, which PyPI ships for Windows as a CPU-only wheel, and the CUDA
index has no 2.13 build, so a plain pip install from that index keeps the
CPU wheel (“already satisfied”). Swap in the newest CUDA build the way
install-windows.bat does (use cu124 instead of cu128 for older
Maxwell/Pascal/Volta GPUs):
pip install --force-reinstall --no-deps --index-url https://download.pytorch.org/whl/cu128 torch torchvision
(--force-reinstall replaces the installed torch; --no-deps keeps every
other lockfile pin, and torch’s own dependencies are already among them.
Installing the full lockfile again brings the CPU wheel back, so run this
again after it.)
On Linux, the lockfile’s torch from PyPI is already a CUDA build (CUDA 13),
so there is nothing to swap. For the CUDA 12.8 build the installers use, run
python scripts/install.py in a fresh virtual environment instead of the
lockfile command above: it leaves the lockfile’s torch and CUDA runtime pins
out and installs torch from the cu128 index.
On macOS (MPS on Apple Silicon) and on CPU-only machines, there is nothing to add: the lockfile’s torch from PyPI already covers them.
3. Install UI dependencies
cd apps/trainer_ui
npm install
cd ../..
Starting the API Server
The API auto-builds the UI on first startup if dist/ is missing or stale.
Windows (quick start):
scripts\windows\start_api_only.bat
Windows (full stack with serving API + UI dev server):
scripts\windows\start_local_windows.bat
Windows (serving API only — ONNX inference, no training deps):
scripts\windows\start_serving_api.bat
macOS (full stack):
bash scripts/macos/start_local_macos.sh
macOS (API only):
bash scripts/macos/start_api.sh
Linux / WSL:
# Activate venv first, then from the repo root:
export SEG_PROJECTS_DIR="$(pwd)/projects"
export SEG_DB_PATH="$(pwd)/projects/app.db"
python -m uvicorn apps.trainer_api.app.main:app --port 8002
# To allow LAN access: set SEG_API_TOKEN, then pass --host 0.0.0.0 AND set
# SEG_HOST=0.0.0.0. Both matter. --host opens the port; SEG_HOST is what
# the startup check reads to decide whether a token is required. Without a
# token the server answers only clients on this machine, so --host on its
# own gets you an open port that returns 401 to everyone else.
The API binds to port 8002. On first launch, heavy modules (PyTorch, OpenCV, scikit-learn) are loaded in the background. A loading screen is shown in the browser until startup completes (~5-15 seconds depending on hardware).
Starting the UI Dev Server
For frontend development with hot-reload:
cd apps/trainer_ui
npm run dev
This starts Vite on http://localhost:5173 with proxy rules that forward API
calls to localhost:8002. Edit React/TypeScript source files and see changes
instantly.
For production builds served directly by the API:
cd apps/trainer_ui
npm run build
Then access the UI at http://localhost:8002/ui/.
Verify Connection
curl http://localhost:8002/api/v1/health
Expected response (JSON with version, disk, RAM, GPU info):
{
"status": "ok",
"version": "0.9.x",
...
}
Other useful endpoints:
| URL | Description |
|---|---|
| http://localhost:8002/ui/ | Built UI (production) |
| http://localhost:8002/docs | Swagger API docs |
| http://localhost:8002/startup-status | Startup progress |
| http://localhost:5173 | Vite dev server (if running) |
Environment Variables
| Variable | Default | Description |
|---|---|---|
SEG_PROJECTS_DIR |
<repo>/projects |
Root directory for all project data |
SEG_DB_PATH |
<repo>/projects/app.db |
SQLite database path |
SEG_MODELS_DIR |
<repo>/models |
Model registry (exported/activated models). SAM checkpoints always live in <repo>/models/sam_checkpoints/ |
LOG_LEVEL |
INFO |
Logging level: DEBUG, INFO, WARNING, ERROR |
LOG_FORMAT |
text |
Log format: text or json |
SEG_HOST |
127.0.0.1 |
Bind address. Set to 0.0.0.0 for LAN access — startup then requires SEG_API_TOKEN |
SEG_API_TOKEN |
(empty) | Shared secret for LAN binds. Required when SEG_HOST is non-loopback; the launchers generate one on the first LAN start |
SEG_TORCH_DEVICE |
auto |
Force device: cuda:0, cpu, or auto |
PYTORCH_CUDA_ALLOC_CONF |
expandable_segments:True |
CUDA memory allocator config (set by start scripts) |
SEG_STARTUP_NO_INSTALL |
(unset) | Set to 1 and startup installs nothing with pip or npm, does not build the UI, and does not re-apply the licence exclusions (scripts/_nc_stubs.py); it only logs the files that still need them. The trainer API test suite sets it (apps/trainer_api/tests/conftest.py) |
SEG_VLM_BACKEND, SEG_VLM_BASE_URL, SEG_VLM_MODEL, SEG_VLM_API_KEY_ENV |
(unset) | The model server behind the AI support panel on the Annotate screen — see the User Guide |
Common Issues
ECONNREFUSED on port 8002
The API server is not running or has not finished starting.
- Check that the API process is alive (look for
uvicornin your process list). - Wait for background startup to complete. The
/startup-statusendpoint returns{"ready": false}until all routers are registered. - Check logs for errors:
- Windows:
logs\windows\trainer_<timestamp>.log(one per start;scripts\windows\status_windows.battails the newest) - macOS:
logs/macos/trainer.log - Linux: console output or
/tmp/seg_trainer.log
- Windows:
CUDA Not Found
python -c "import torch; print(torch.cuda.is_available())"
If this prints False:
- Verify NVIDIA driver is installed:
nvidia-smi - On Windows, swap in CUDA-enabled PyTorch (see
Install Python dependencies):
pip install --force-reinstall --no-deps --index-url https://download.pytorch.org/whl/cu128 torch torchvisionOn Linux, the lockfile’s CUDA 13 build needs a driver that supports CUDA 13; with an older driver, set up the CUDA 12.8 build as described there.
- Ensure
CUDA_HOME/CUDA_PATHare set if using a non-standard install.
Vite Proxy Errors (404 on API calls from dev server)
The Vite dev server proxies API calls to localhost:8002. If the API is running
on a different host or port, edit apps/trainer_ui/vite.config.mjs:
proxy: {
"/api": { target: "http://YOUR_API_HOST:8002", ws: true },
// ... other routes (/v2, /ws, /health, /version, /startup-status)
}
TypeScript Build Errors
cd apps/trainer_ui
npx tsc --noEmit
Fix any reported type errors before committing. The production build
(npm run build) runs tsc -b first and will fail on type errors.
Port Already in Use
# Windows
netstat -ano | findstr :8002
# macOS / Linux
lsof -i :8002
Kill the conflicting process or choose a different port with --port.
Blank White Page at /ui/
The UI has not been built. Run:
cd apps/trainer_ui
npm install
npm run build
Or start the Vite dev server (npm run dev) and access http://localhost:5173.
Stopping Services
Windows:
scripts\windows\stop_local_windows.bat
macOS:
bash scripts/macos/stop_local_macos.sh
Linux:
# If started in foreground, Ctrl+C stops uvicorn.
# If backgrounded:
pkill -f "uvicorn apps.trainer_api"
Running Tests
See scripts/test.sh (Linux/WSL) or scripts/test.bat (Windows) for the
unified test runner that checks TypeScript, linting, Python imports, and
optionally E2E tests.
# Linux / WSL
bash scripts/test.sh
# Windows
scripts\test.bat