- Version: 20261019
- Source Code Copyright: MIT License — amdegroot/ssd.pytorch
- Redistribution Restriction: This source code is integrated by LEADERG INC. Please use it privately. Please DO NOT distribute it to internet.
Console/terminal pipeline for object detection with SSD512 on a ResNet-152 backbone (PyTorch), supporting Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon). The engine lives under src/ssd/ and is configured by data/{dataset}/ssd_res152_voc.yaml (512x512, Pascal-VOC-XML annotations). The example dataset plate ships with a trained checkpoint and the ImageNet ResNet-152 backbone — inference works out of the box.
Training and inference run on the GPU — CUDA on Windows/Linux, MPS on Apple Silicon — and fall back to the CPU automatically (fine for inference, very slow for training). Progress is printed to the console.
[Folder Structure]
- CLAUDE.md / AGENTS.md: Program specification (identical content).
- CHANGELOG.md: Change log.
- copyright.txt: Copyright notice.
- Image-Object-Detection-ResNet152-SSD512-PyTorch-Python.html: This document (usage page).
- 1512.03385.pdf: ResNet reference paper.
- data/{dataset}/: ssd_res152_voc.yaml, labels.txt, train|valid|test/image + annotation (+ index txts).
- model/{dataset}/: ssd_res50_epoch_3340_512.pth (trained), pretrained_resnet152-b121ed2d.pth (backbone), new training checkpoints ssd_res50_epoch_{N}_512.pth, output/ (annotated results).
- src/ssd/: Engine (train.py, inference*.py, demo.py, layers/, models/, data/, utils/, configs/).
- src/annotation/: Bundled aiohttp annotation server (port 8801).
- tool/tools.py: Shared helpers (project_root, select_device, delete_ipynb_checkpoints).
- src/: Wrapper entry points and launcher scripts (01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh, 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh, 03–09, 99).
- venv/: Python virtual environment, created by 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh.
[Prerequisites]
- Python 3.14, installed by 01_python_install_windows.bat (winget), 01_python_install_linux.sh (apt; adds the deadsnakes PPA when needed; needs sudo) or 01_python_install_mac.sh (Homebrew).
- The venv scripts install PyTorch 2.13.0 + torchvision 0.28.0 first, then src/requirements.txt (numpy, Pillow, opencv-python, matplotlib, PyYAML, six, pycocotools, aiohttp + aiohttp-jinja2 + jinja2 for the annotation server).
- Windows / Linux: the CUDA 13.0 (cu130) build. GPU use needs an NVIDIA Turing or newer GPU (GTX 16 / RTX 20 series and later) and a driver supporting CUDA 13.0 or newer (check nvidia-smi). Without an NVIDIA GPU the same build runs on the CPU.
- macOS: the PyPI build, which uses the Apple GPU through MPS. PyTorch 2.13.0 ships macOS wheels for Apple Silicon (arm64, macOS 14+) only; Intel Macs are not supported.
- Windows 11 uses the .bat launchers; Ubuntu 24.04 and macOS use the .sh launchers. Inference is fast on any device; training realistically wants a GPU.
[Launcher Scripts]
1. 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh
Install Python 3.14 (winget / apt + deadsnakes PPA / Homebrew). Skips when it is already installed.
2. 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh
Delete the old venv/, create a fresh one with Python 3.14, install PyTorch 2.13.0 + torchvision 0.28.0 (cu130 on Windows/Linux, PyPI/MPS build on macOS), then src/requirements.txt. Aborts loudly if pip fails; prints whether CUDA (or MPS) is available.
3. 03_venv_activate.bat / 03_venv_activate.sh
Activate the venv. On Linux/macOS, source it: source src/03_venv_activate.sh. If the project folder was renamed after the venv was created, re-create the venv with 02_venv_create_windows/linux/mac first; the other launchers do not need activation.
4. 04_annotation.bat / 04_annotation.sh
Annotation web UI on port 8801 (--dataset --split train|valid|test --port).
5. 05_prepare.bat / 05_prepare.sh
Regenerate train.txt, valid.txt, labels.txt.
6. 06_train.bat / 06_train.sh
Train the detector (CUDA → MPS → CPU). Checkpoints land in model/{dataset}/.
7. 07_inference.bat / 07_inference.sh
Detect in a single image (default data/plate/test/image/inclusion-9.jpg).
8. 08_inference_folder.bat / 08_inference_folder.sh
Detect in every image of a folder (default data/{dataset}/test/image).
9. 09_inference_folder_1.bat / 09_inference_folder_1.sh
Folder inference with underkill/overkill/right-rate statistics (threshold 0.7).
10. 99_venv_clean.bat / 99_venv_clean.sh
Delete the venv/ folder.
11. 99_venv_deactivate.bat / 99_venv_deactivate.sh
Deactivate the venv in the current shell. On Linux/macOS, source it: source src/99_venv_deactivate.sh (bash or zsh).
All launchers cd to the project root and forward extra arguments (e.g. src\07_inference.bat --device cpu).
[Python Entry Points]
src/annotation_server.py
--dataset plate --split train --port 8801 [--no-browser]. Pascal-VOC-XML annotation UI; writes the XML files and image_annotation_classes.txt.
src/prepare.py
--dataset plate. Writes train.txt/valid.txt (image stems) and labels.txt (BACKGROUND + classes).
src/train.py
--dataset plate [--cfg YAML] [--resume PATH] [--device auto]. Yaml drives LR 0.0001 / 10000 epochs / batch 1; starts from the ImageNet ResNet-152 backbone; checkpoints (every 20 epochs and at the end) land in model/{dataset}/. Progress (loss every 10 iterations, validation loss every 10 epochs) is printed to the console only.
src/inference.py
--dataset plate [--source FILE|FOLDER] [--weights PATH] [--threshold 0.7] [--stats] [--show] [--device auto]. File = single image; folder = every image; --stats = right-rate statistics. Annotated results land in model/{dataset}/output/.
--device: auto (default) picks CUDA → MPS → CPU; cuda, cuda:N, mps or cpu forces a device. The selected device is printed once at startup.
[Quick Start]
Windows 11
src\01_python_install_windows.bat
src\02_venv_create_windows.bat
src\07_inference.bat
src\08_inference_folder.bat
src\06_train.bat (GPU machine)
Open a new terminal after 01_python_install_windows.bat before running 02_venv_create_windows.bat.
Ubuntu 24.04
bash src/01_python_install_linux.sh
bash src/02_venv_create_linux.sh
bash src/07_inference.sh
bash src/08_inference_folder.sh
bash src/06_train.sh (GPU machine)
macOS 14+ (Apple Silicon)
bash src/01_python_install_mac.sh
bash src/02_venv_create_mac.sh
bash src/07_inference.sh
bash src/08_inference_folder.sh
bash src/06_train.sh
Full workflow for your own data: 04_annotation (label) → 05_prepare (index files; set NUM_CLASSES = classes + 1 in the yaml) → 06_train → 07–09 inference.
[GPU]
- Device order: CUDA → MPS → CPU (select_device in tool/tools.py), overridable with --device.
- Windows / Linux: 02_venv_create_windows.bat / 02_venv_create_linux.sh install the CUDA 13.0 (cu130) build directly — no extra step. It needs a Turing-or-newer NVIDIA GPU and a driver supporting CUDA 13.0+ (nvidia-smi). Pascal/Volta GPUs (GTX 10xx, V100) are not supported by cu130; on those, reinstall torch from the cu126 index inside the venv: pip install torch==2.13.0 torchvision==0.28.0 --index-url https://download.pytorch.org/whl/cu126 --force-reinstall
- macOS (Apple Silicon): the model, prior boxes, loss targets and detections run on MPS; PYTORCH_ENABLE_MPS_FALLBACK=1 is set by every entry script so ops MPS lacks fall back to the CPU. cudnn and DataParallel are CUDA-only.
- Without a usable GPU everything runs on the CPU (fine for inference, very slow for training).
- Checkpoints are loaded on the CPU and then copied onto the selected device, so they load on CUDA, MPS and CPU alike.
[References]
- ResNet paper (He et al. 2015, shipped as 1512.03385.pdf): arxiv.org/abs/1512.03385
- SSD paper (Liu et al. 2015): arxiv.org/abs/1512.02325
- PyTorch install: pytorch.org/get-started/locally
- PyTorch MPS backend: docs.pytorch.org/docs/stable/notes/mps.html
This SDK is built in AppForAI - AI Dev Tools.