项目地址: https://cnb.cool/code_free/dogs-cnn
基于深度学习的细粒度犬种识别系统,支持11种常见犬种的精准分类,提供现代化的Web界面和完整的训练推理流水线。
| 中文名 | 英文名 | 类别ID |
|---|---|---|
| 吉娃娃 | Chihuahua | 0 |
| 中华田园犬 | Chinese Rural Dog | 1 |
| 杜宾犬 | Doberman | 2 |
| 法国斗牛犬 | French Bulldog | 3 |
| 德国牧羊犬 | German Shepherd | 4 |
| 金毛寻回犬 | Golden Retriever | 5 |
| 哈士奇 | Husky | 6 |
| 拉布拉多猎犬 | Labrador | 7 |
| 萨摩耶犬 | Samoyed | 8 |
| 柴犬 | Shiba Inu | 9 |
| 藏獒 | Tibetan Mastiff | 10 |
dogs-cnn/ ├── src/ # 源代码目录 │ ├── app/ # 应用模块 │ ├── core/ # 核心功能 │ │ ├── training/ # 训练相关 │ │ ├── inference/ # 推理相关 │ │ ├── models/ # 模型定义 │ │ └── data/ # 数据处理 │ ├── utils/ # 工具函数 │ ├── config/ # 配置文件 │ ├── __init__.py │ ├── model.py # 模型定义与加载 │ ├── predict.py # 推理接口 │ ├── train.py # 训练入口 │ ├── dataProcess.py # 数据预处理 │ ├── My_dataLoader.py # 数据加载器 │ └── labels.py # 标签映射 ├── models/ # 模型权重目录 ├── data_split/ # 处理后的数据集 │ ├── train/ # 训练集 │ ├── val/ # 验证集 │ └── test/ # 测试集 ├── pet_dog/ # 原始数据目录 ├── scripts/ # 脚本目录 │ ├── train.sh # 训练脚本 │ └── run_app.sh # 应用启动脚本 ├── requirements.txt # Python依赖 ├── README.md # 项目说明 └── .cnb.yml # 部署配置
# 安装依赖
pip install -r requirements.txt
# 或使用conda创建环境
conda create -n dog-cnn python=3.9
conda activate dog-cnn
pip install -r requirements.txt
# 自动分割数据集(训练/验证/测试)
python -m src.dataProcess
# 查看数据统计
python -c "
from src.dataProcess import print_split_stats
print_split_stats('data_split')
"
# 使用默认配置训练
bash ./scripts/train.sh
# 或手动训练
python -m src.train --epochs 50 --batch-size 32 --lr 1e-4
# 启动Streamlit应用
bash ./scripts/run_app.sh
# 或直接运行
streamlit run src/app/app.py
## 🌐 在线访问
项目已部署在 CNB 平台,可直接访问使用:
- **应用地址**: https://cnb.cool/code_free/dogs-cnn
- **Git 仓库**: https://cnb.cool/code_free/dogs-cnn.git
EnhancedDogBreedCNN (推荐)
DogBreedCNN (基础)
在标准测试集上的表现:
| 指标 | 数值 |
|---|---|
| 训练准确率 | ~98.5% |
| 验证准确率 | ~92.3% |
| 测试准确率 | ~91.8% |
| 推理速度 (GPU) | ~15ms/张 |
| 推理速度 (CPU) | ~120ms/张 |
from src.predict import batch_predict
# 批量处理图片列表
image_paths = ['dog1.jpg', 'dog2.jpg', 'dog3.jpg']
results = batch_predict(image_paths, model_path='models/best_model.pth')
from src.predict import tta_predict
# 使用测试时增强
probs = tta_predict('dog.jpg', hflip=True, scales=[1.0, 1.2])
from src.model import export_to_onnx
# 导出为ONNX格式
model = load_model('models/best_model.pth')
export_to_onnx(model, 'models/model.onnx')
A: 启用自动批次大小调整,或减小--batch-size参数
A: 确保训练数据充足,尝试启用TTA增强
A: 在src/labels.py中添加映射,重新准备数据并训练
A: 检查模型路径,确保使用兼容的PyTorch版本
欢迎提交Issue和合并请求!
git clone https://cnb.cool/code_free/dogs-cnn.git)git checkout -b feature/你的功能名称)git commit -m 描述你的更改(如:Add new dog breed label))git push origin feature/你的功能名称)本项目采用MIT许可证,详见LICENSE文件。
注意: 本项目仅供学习和研究使用。商业使用请确保遵守相关法律法规。