• Version: 20261019
  • Source Code Copyright: Apache License 2.0 — lukemelas/EfficientNet-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 training and running an ResNeXt-101 image classifier (PyTorch), supporting Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon). The engine scripts live under src/examples/imagenet/ and support several architectures via --arch (ResNeXt-101 by default). The example dataset plate (steel-plate surface defects, 6 classes: CR/IN/PA/PS/RS/SC) ships with a trained ResNeXt-101 checkpoint, so 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.

 

[Folder Structure]

  • CLAUDE.md / AGENTS.md: Program specification (identical content).
  • CHANGELOG.md: Change log.
  • copyright.txt: Copyright notice.
  • Image-Classification-ResNeXt101-PyTorch-Python.html: This document (usage page).
  • data/{dataset}/: labels_map.txt (class list, regenerated by training) + train/, val/, test/ in torchvision ImageFolder layout (one subfolder per class).
  • model/{dataset}/: model_best.pth.tar (best checkpoint), checkpoint.pth.tar (latest), ImageNet-pretrained resnext101_32x8d / resnext50_32x4d .pth weights.
  • tool/tools.py: Shared helpers (select_device: CUDA → MPS → CPU, count_classes, ...).
  • src/: Wrapper entry points, engine (examples/imagenet/), launcher scripts and requirements.txt.
  • 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 src\01_python_install_windows.bat (winget), src/01_python_install_linux.sh (apt, deadsnakes PPA when needed; uses sudo) or src/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, efficientnet_pytorch).
  • Windows / Linux: the CUDA 13.0 (cu130) build. GPU use needs an NVIDIA Turing or newer GPU (GTX 16 / RTX 20 series and later) with a driver supporting CUDA 13.0 or newer (check nvidia-smi); without one the same build runs on the CPU.
  • macOS: the PyPI build, using the Apple GPU through MPS. Apple Silicon (arm64) with macOS 14+ only; Intel Macs are not supported by PyTorch 2.13.0.

[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 / 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 (CUDA 13.0 build 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_train.bat / 04_train.sh

Train the classifier (defaults: plate, resnext101_32x8d, 50000 epochs, batch 16; resumes from model_best.pth.tar when present).

 

5. 05_inference.bat / 05_inference.sh

Classify a single image (default data/plate/test/IN/IN-1.png).

 

6. 06_inference_folder.bat / 06_inference_folder.sh

Classify every image in a folder (default data/{dataset}/test) with Acc@1/Acc@5.

 

7. 07_inference_folder_topk.bat / 07_inference_folder_topk.sh

Folder inference with underkill/overkill/right-rate statistics.

 

8. 99_venv_clean.bat / 99_venv_clean.sh

Delete the venv/ folder.

 

9. 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).

 

Extra arguments are forwarded to the Python entry point, e.g. src\05_inference.bat --device cpu.

[Python Entry Points]

src/train.py

--dataset plate --arch resnext101_32x8d --batch-size 16 --image-size 512 --epochs 50000 --learning-rate 0.0001 --workers 4 --device auto [--num-classes N] [--resume PATH|""] [--pretrained PATH]. The class count is derived from the data/{dataset}/train class folders. Resumes from model/{dataset}/model_best.pth.tar when it exists (continuing from its epoch, so --epochs must be larger); --resume "" trains from scratch. Checkpoints land in model/{dataset}/; progress is printed to the console.

 

src/inference.py

--dataset plate --arch resnext101_32x8d --source FILE|FOLDER --batch-size 16 --image-size 512 --device auto [--num-classes N] [--weights PATH] [--topk-right] [--show]. A file source classifies one image; a folder source reports Acc@1/Acc@5 over all images; --topk-right switches folder mode to the underkill/overkill/right-rate variant; --show displays each image (requires a desktop session).

 

--device: auto (default) picks CUDA → MPS → CPU; cuda, cuda:N, mps or cpu forces a device. The selected device is printed at startup.

[Quick Start]

Windows 11

src\01_python_install_windows.bat

src\02_venv_create_windows.bat

src\05_inference.bat

src\06_inference_folder.bat

src\04_train.bat

 

Ubuntu 24.04

bash src/01_python_install_linux.sh

bash src/02_venv_create_linux.sh

bash src/05_inference.sh

bash src/06_inference_folder.sh

bash src/04_train.sh

 

macOS 14+ (Apple Silicon)

bash src/01_python_install_mac.sh

bash src/02_venv_create_mac.sh

bash src/05_inference.sh

bash src/06_inference_folder.sh

bash src/04_train.sh

Inference works out of the box with the shipped checkpoint. Training realistically wants a GPU.

[GPU]

  • Device order: CUDA → MPS → CPU, overridable with --device.
  • Windows / Linux: the venv scripts install the CUDA 13.0 (cu130) build directly. It needs a Turing-or-newer NVIDIA GPU and a driver supporting CUDA 13.0+. 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 runs on the Apple GPU through MPS; ops MPS lacks fall back to the CPU (PYTORCH_ENABLE_MPS_FALLBACK=1 is set by the entry scripts).
  • Without a usable GPU everything runs on the CPU (slow for training). Checkpoints load on any device.

[References]

 

This SDK is built in AppForAI - AI Dev Tools.