- Version: 20261019
- Source Code Copyright: MIT License — kenshohara/3D-ResNets-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 video action classification with 3D-ResNets (PyTorch), supporting Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon). The vendored engine (kenshohara/3D-ResNets-PyTorch) lives under src/resnets3d/. The example dataset is an HMDB51 subset with two actions (golf / jump): source videos, extracted jpg frames, split lists, and a trained ResNet-50 checkpoint (save_200.pth) all ship with the project. Training and inference run on the GPU (CUDA on Windows/Linux, MPS on Apple Silicon) and fall back to the CPU automatically.
Workflow: videos → per-frame jpg folders (ffmpeg) → annotation JSON → train → inference on the validation split.
[Folder Structure]
- CLAUDE.md / AGENTS.md: Program specification (identical content).
- CHANGELOG.md: Change log.
- copyright.txt: Copyright notice.
- Image-Classification-3D-ResNets-Python.html: This document (usage page).
- 2004.04968.pdf: Reference paper.
- data/hmdb_videos/: hmdb51_org/{class}/ source videos; jpg/{class}/{video}/ extracted frames (step 04); annotation/ HMDB51 split lists; json/ annotation JSONs (step 05).
- model/hmdb_videos/: save_{epoch}.pth checkpoints, opts.json, train/val logs, and inference_results/val.json (step 07).
- src/resnets3d/: Vendored 3D-ResNets engine (main.py, models/, util_scripts/, bundled Windows ffmpeg.exe/ffprobe.exe).
- tool/tools.py: Shared helpers (select_device / resolve_device: CUDA → MPS → CPU, ...).
- 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, h5py, joblib, pandas, scikit-learn).
- 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.
- ffmpeg (step 04 only): Windows uses the bundled src/resnets3d/ffmpeg.exe automatically; Ubuntu: sudo apt install ffmpeg; macOS: brew install ffmpeg. Steps 05-07 do not need ffmpeg.
[Launcher Scripts]
Windows uses the batch files (.bat); Ubuntu Linux and macOS share the shell scripts (.sh). All launchers switch to the project root and forward extra arguments.
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_convert_video.bat / 04_convert_video.sh
Videos → per-frame jpg folders with ffmpeg (Windows: bundled exe; Ubuntu: sudo apt install ffmpeg; macOS: brew install ffmpeg).
5. 05_generate_annotation.bat / 05_generate_annotation.sh
Split lists + jpg folders → hmdb51_1/2/3.json.
6. 06_train.bat / 06_train.sh
Train the 3D-ResNet (defaults: 2 classes, ResNet-50, batch 8, 200 epochs, checkpoint every 5).
7. 07_inference.bat / 07_inference.sh
Inference on the validation split; per-video top-k predictions → model/hmdb_videos/inference_results/val.json.
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\07_inference.bat --device cpu.
[Python Entry Points]
src/convert_video.py
--dataset hmdb_videos --video-dir data/{ds}/hmdb51_org --jpg-dir data/{ds}/jpg --dataset-format hmdb51. Puts the bundled Windows ffmpeg on PATH automatically and verifies ffmpeg/ffprobe exist. CPU only (ffmpeg).
src/generate_annotation.py
--dataset hmdb_videos. Writes the three annotation JSONs from annotation/ + jpg/. CPU only.
src/train.py
--dataset hmdb_videos --classes 2 --model-depth 50 --batch-size 8 --threads 2 --epochs 200 --checkpoint 5 --device auto [--resume {ckpt}]. Checkpoints/logs land in model/{ds}/; progress is printed to the console. Realistic training needs a GPU.
src/inference.py
--dataset hmdb_videos --classes 2 --model-depth 50 --weights model/{ds}/save_200.pth --topk 1 --threads 2 --device auto. Writes val.json; also runs fine on the CPU (~0.4 s per video).
--device: auto (default) picks CUDA → MPS → CPU; cuda, cuda:N, mps or cpu forces a device (the older 0 = cuda:0 and -1 = cpu still work). An unavailable CUDA/MPS request falls back to the automatic choice with a warning. The selected device is printed at startup.
[Quick Start]
Windows 11
src\01_python_install_windows.bat
src\02_venv_create_windows.bat
src\07_inference.bat
Ubuntu 24.04
bash src/01_python_install_linux.sh
bash src/02_venv_create_linux.sh
bash src/07_inference.sh
macOS 14+ (Apple Silicon)
bash src/01_python_install_mac.sh
bash src/02_venv_create_mac.sh
bash src/07_inference.sh
Inference works out of the box (frames, JSON, and save_200.pth all ship). Full pipeline from raw videos: 04 → 05 → 06 → 07.
[Dataset Format (HMDB51 style)]
- hmdb51_org/{class}/*.avi — source videos, one folder per class.
- annotation/{class}_test_split{1|2|3}.txt — official HMDB51 split lists (1 = train, 2 = validation).
- Step 04 extracts each video to jpg/{class}/{video}/image_%05d.jpg; step 05 combines splits + frame counts into the JSON files the engine consumes.
- Your own actions: mirror this layout with your own classes/videos and split lists, then pass --classes {n} to steps 06/07.
[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
- On CUDA the model is wrapped in DataParallel; cudnn.benchmark and pinned DataLoader memory are enabled.
- 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 train.py, inference.py and the engine main.py).
- Without a usable GPU everything runs on the CPU (fine for inference, slow for training). Checkpoints load on any device.
[References]
- Paper (Kataoka et al., shipped as 2004.04968.pdf): https://arxiv.org/abs/2004.04968
- 3D-ResNets-PyTorch source: https://github.com/kenshohara/3D-ResNets-PyTorch
- HMDB51 dataset: serre-lab.clps.brown.edu
- PyTorch installation: https://pytorch.org/get-started/locally/
- PyTorch MPS backend: https://docs.pytorch.org/docs/stable/notes/mps.html
After execution, you can see the results of 3D ResNets inference.
This SDK is built in AppForAI - AI Dev Tools.