BaoShi is a 25-class gem image classification project. For final course
submission, the main implementation is the PyTorch-GPU version using
torchvision.models.resnet18 for transfer learning.
The earlier PaddlePaddle-GPU implementation and notebooks are kept in the repository as historical experiment versions so the project can be rolled back. Original notebooks are not deleted.
All Python, pip, and Jupyter commands in this project must use the project virtual environment explicitly:
C:\Documents\PyCharm\BaoShi\.venv\Scripts\python.exeDo not use bare python, pip, or py in this project.
Check the interpreter:
C:\Documents\PyCharm\BaoShi\.venv\Scripts\python.exe -c "import sys; print(sys.executable)"Check PyTorch-GPU:
C:\Documents\PyCharm\BaoShi\.venv\Scripts\python.exe -c "import torch; print('torch=', torch.__version__); print('cuda=', torch.cuda.is_available()); print('device=', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU')"The PyTorch version uses:
- framework: PyTorch-GPU
- backbone:
torchvision.models.resnet18 - checkpoint:
checkpoints/GemResNet18_best_pytorch.pth - training log:
results/experiment_log_pytorch.md - batch prediction CSV:
results/batch_predict_results_pytorch.csv - input size:
224x224 - normalization: ImageNet mean/std
- device:
torch.device("cuda" if torch.cuda.is_available() else "cpu")
Current PyTorch-GPU result:
- best validation accuracy:
0.8765 - checkpoint:
checkpoints/GemResNet18_best_pytorch.pth - default prediction:
alexandrite_3.jpg -> Alexandrite - batch test images:
4/4 correct
Prepare data:
C:\Documents\PyCharm\BaoShi\.venv\Scripts\python.exe src\gem_classifier\data.pyTrain:
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\run_train_torch.ps1Evaluate:
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\run_evaluate_torch.ps1Single-image prediction:
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\run_predict_torch.ps1Batch prediction:
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\run_batch_predict_torch.ps1Start the PyTorch Gradio UI:
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\run_gradio_app_torch.ps1If port 7860 is occupied:
$env:GRADIO_SERVER_PORT="7861"
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\run_gradio_app_torch.ps1src/gem_classifier/
├─ config.py
├─ data.py
├─ datasets_torch.py
├─ models/
│ ├─ resnet18.py
│ └─ resnet18_torch.py
├─ train_torch.py
├─ evaluate_torch.py
├─ predict_torch.py
├─ batch_predict_torch.py
└─ app_gradio_torch.py
The PaddlePaddle implementation remains available for comparison:
- checkpoint:
checkpoints/GemResNet18_best.pdparams - archived checkpoint:
checkpoints/archive/GemResNet18_acc9091.pdparams - historical validation accuracy:
0.9091 - batch prediction CSV:
results/batch_predict_results.csv - Gradio app:
src/gem_classifier/app_gradio.py
PaddlePaddle commands are retained for rollback only; the final submitted framework is PyTorch-GPU.
The current dataset has:
- classes: 25
- train images: 730
- eval images: 81
- default test directory:
home\aistudio\data\archive_test - label map:
label_map.json
The data script ignores __MACOSX and counts classes from the dataset
directories.