Console / terminal pipeline for training and running a PreAct-ResNet18 image classifier (PyTorch), supporting Windows 11 and Ubuntu Linux 24.04. The engine scripts live under src/examples/imagenet/ and support several architectures via --arch, with PreAct-ResNet18 as the default. The example dataset plate (steel-plate surface defects, 6 classes: CR / IN / PA / PS / RS / SC) ships with a trained PreAct-ResNet18 checkpoint, so inference works out of the box.

[Folder Structure]

  • CLAUDE.md / AGENT.md: program specification, the two files are kept identical.
  • CHANGELOG.md: change log.
  • copyright.txt: copyright notice.
  • 1603.05027.pdf: the PreAct-ResNet (Identity Mappings) reference paper.
  • data/{dataset}/: labels_map.txt (the 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) and logs/ (TensorBoard).
  • tool/tools.py: shared helpers.
  • src/: wrapper entry points, the engine (examples/imagenet/), the launcher scripts and this document.
  • venv/: Python virtual environment, created by step 01.

[Instructions]

1. 01_venv_create.bat / 01_venv_create.sh

Delete the old venv/, create a fresh one, and install src/requirements.txt. Aborts loudly if pip fails.

 

2. 02_venv_activate.bat / 02_venv_activate.sh

Activate the venv. On Linux, source it: source src/02_venv_activate.sh.

 

3. 03_train.bat / 03_train.sh

Train the classifier. Defaults: plate, preactresnet18, 500 epochs, batch 4. Resumes from model_best.pth.tar when present.

 

4. 04_tensorboard.bat / 04_tensorboard.sh

Start TensorBoard on model/{dataset}/logs. Positional arguments: [dataset] [port], defaulting to plate and 6066.

 

5. 05_inference.bat / 05_inference.sh

Classify a single image. The default is data/plate/test/IN/IN-1.png.

 

6. 06_inference_folder.bat / 06_inference_folder.sh

Classify every image in a folder, by default data/{dataset}/test, reporting Acc@1 and Acc@5.

 

7. 07_inference_folder_topk.bat / 07_inference_folder_topk.sh

Folder inference reporting underkill, overkill and right-rate statistics instead.

 

8. 99_venv_clear.bat / 99_venv_clear.sh

Delete the venv/ folder.

 

[Python Entry Points]

src/train.py

Arguments and defaults:

  • --dataset plate: the dataset folder name
  • --arch preactresnet18: the network architecture
  • --batch-size 18: the batch size
  • --image-size 512: the image size
  • --epochs 50000: the number of epochs
  • --learning-rate 0.0005: the learning rate
  • --workers 4: the number of data-loading workers
  • --num-classes: the class count (optional)
  • --resume: the checkpoint path to resume from (optional)
  • --pretrained: the pretrained weights path (optional)

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 --resume with an empty string to train from scratch. Checkpoints land in model/{dataset}/ and TensorBoard logs in model/{dataset}/logs/, which is cleared on every run.

 

src/inference.py

Arguments and defaults:

  • --dataset plate: the dataset folder name
  • --arch preactresnet18: the network architecture
  • --source: the input, either a single file or a folder
  • --batch-size 18: the batch size
  • --image-size 512: the image size
  • --num-classes: the class count (optional)
  • --weights: the model weights path (optional)
  • --topk-right: report underkill, overkill and right-rate statistics instead (optional)
  • --show: display each image (optional, requires a desktop session)

A file source classifies one image; a folder source reports Acc@1 and Acc@5 over all images. Adding --topk-right switches folder mode to the underkill / overkill / right-rate variant.

[Quick Start]

Windows 11

src\01_venv_create.bat

src\05_inference.bat

src\06_inference_folder.bat

src\03_train.bat

src\04_tensorboard.bat

 

Ubuntu 24.04

bash src/01_venv_create.sh

bash src/05_inference.sh

bash src/06_inference_folder.sh

bash src/03_train.sh

bash src/04_tensorboard.sh

 

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

[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 nvidia-smi). For example, with a CUDA 12.8 driver:

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]

 

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.