A console/terminal pipeline for training and running a VGG-16 image classifier with PyTorch, supporting Windows 11 and Ubuntu Linux 24.04. The engine scripts live under src/examples/imagenet/ and support several architectures through --arch (vgg16 by default). The example dataset plate contains steel-plate surface defect images in 6 classes (CR, IN, PA, PS, RS, SC) and ships with a trained VGG-16 checkpoint, so inference works out of the box.
[Folder Structure]
- CLAUDE.md / AGENT.md: program specification (identical content).
- CHANGELOG.md: change log.
- copyright.txt: copyright notice.
- 1409.1556.pdf: VGG reference paper.
- data/{dataset}/: labels_map.txt (class list, regenerated by training) plus train/, val/ and test/ in torchvision ImageFolder layout (one subfolder per class).
- model/{dataset}/: model_best.pth.tar (best checkpoint), checkpoint.pth.tar (latest), logs/ (TensorBoard).
- tool/tools.py: shared helpers.
- src/: Python entry points, engine (examples/imagenet/), launcher scripts and this document.
- venv/: Python virtual environment, created by step 01.
[Prerequisites]
- Operating system: Windows 11 or Ubuntu Linux 24.04.
- Python 3 and pip.
- An NVIDIA GPU is recommended for training; inference also runs on CPU.
[Instructions]
Step 1: Create the virtual environment (CPU)
Delete the old venv/, create a fresh one and install the packages listed in src/requirements.txt. The script aborts loudly if pip fails.
Windows: src\01_venv_create.bat
Linux: bash src/01_venv_create.sh
Step 2: Create the virtual environment (GPU)
Same as step 1, but swaps torch for the CUDA 12.8 (cu128) build, for machines with an NVIDIA GPU (driver CUDA version 12.8 or later, check with nvidia-smi).
Windows: src\01_venv_create_gpu.bat
Linux: bash src/01_venv_create_gpu.sh
Step 3: Activate the virtual environment
Activate the venv. On Linux, source the script.
Windows: src\02_venv_activate.bat
Linux: source src/02_venv_activate.sh
Step 4: Train the model
Train the image classifier. Defaults: dataset plate, architecture vgg16, 500 epochs, batch size 24, image size 512, learning rate 0.0001. Training resumes from model_best.pth.tar when that file is present.
Windows: src\03_train.bat
Linux: bash src/03_train.sh
Step 5: Watch the training curves
Open the training logs in model/{dataset}/logs with TensorBoard. It accepts two positional arguments, [dataset] and [port], defaulting to plate and 6066.
Windows: src\04_tensorboard.bat
Linux: bash src/04_tensorboard.sh
Step 6: Classify a single image
Classify one image, by default data/plate/test/SC/SC-1.png.
Windows: src\05_inference.bat
Linux: bash src/05_inference.sh
Step 7: Classify a whole folder
Classify every image in a folder (data/{dataset}/test by default) and report Acc@1 and Acc@5.
Windows: src\06_inference_folder.bat
Linux: bash src/06_inference_folder.sh
Step 8: Folder inference with underkill and overkill statistics
Same as step 7, but additionally reports underkill, overkill and right-rate statistics.
Windows: src\07_inference_folder_topk.bat
Linux: bash src/07_inference_folder_topk.sh
Step 9: Remove the virtual environment
Delete the venv/ folder.
Windows: src\99_venv_clear.bat
Linux: bash src/99_venv_clear.sh
[Python Entry Points]
- src/train.py: --dataset plate --arch vgg16 --batch-size 24 --image-size 512 --epochs 500 --learning-rate 0.0001 --workers 4 [--num-classes N] [--resume PATH] [--pretrained PATH]. The class count is derived from the class folders under data/{dataset}/train. Training resumes from model/{dataset}/model_best.pth.tar when it exists; pass an empty --resume to train from scratch. Checkpoints land in model/{dataset}/ and TensorBoard logs in model/{dataset}/logs/ (cleared per run).
- src/inference.py: --dataset plate --arch vgg16 --source FILE|FOLDER --batch-size 24 --image-size 512 [--num-classes N] [--weights PATH] [--topk-right] [--show]. A file source classifies one image; a folder source reports Acc@1 and Acc@5 over all images; --topk-right switches folder mode to the underkill/overkill/right-rate variant; --show displays each image and requires a desktop session.
[GPU]
The default PyPI torch wheel is CPU-only on Windows. For an NVIDIA GPU, install the build matching your driver's CUDA version (check with nvidia-smi), for example CUDA 12.8:
pip uninstall -y torch torchvision
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
The engine auto-detects CUDA and falls back to CPU when it is unavailable.
[References]
- Very Deep Convolutional Networks (Simonyan & Zisserman 2014, shipped as 1409.1556.pdf): https://arxiv.org/abs/1409.1556
- EfficientNet-PyTorch (vendored repository): https://github.com/lukemelas/EfficientNet-PyTorch
- Extra architectures: https://github.com/zjZSTU/GoogLeNet, https://github.com/weiaicunzai/pytorch-cifar100, https://github.com/d-li14/mobilenetv3.pytorch
- PyTorch install: https://pytorch.org/get-started/locally/
This SDK is built in AppForAI - AI Dev Tools.
Purchase license separately: USD 400, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.