---
title: cat_dog_classifier_gpu
canonical_url: "https://www.modelscope.cn/models/gzwebsj/cat_dog_classifier_gpu"
md_url: "https://www.modelscope.cn/models/gzwebsj/cat_dog_classifier_gpu.md"
repository: gzwebsj/cat_dog_classifier_gpu
chinese_name: "猫狗分类模型 GPU版"
last_updated: 2026-07-14
library_name:
  - gguf
downloads: 51
stars: 0
tags:
  - gguf
---

# cat_dog_classifier_gpu

> cat_dog_classifier_gpu - gzwebsj 在 ModelScope 开源的模型。体验地址：http://154.12.16.239:8080/catdog

- **Repository**: gzwebsj/cat_dog_classifier_gpu
- **Tags**: gguf
- **Downloads**: 51
- **Stars**: 0
- **Last updated**: 2026-07-14

Source: https://www.modelscope.cn/models/gzwebsj/cat_dog_classifier_gpu

---

## 体验地址：http://154.12.16.239:8080/catdog

# cat_dog_classifier_gpu

猫狗分类模型 - 基于 ResNet18 的二分类图像分类模型

## 模型信息

- **骨干网络**: ResNet18
- **分类类别**: Cat, Dog (2类)
- **训练数据**: 24998 张图片
- **验证准确率**: 98.64%
- **训练设备**: NVIDIA GeForce GTX 1060
- **模型格式**: GGUF (42.64 MB)

## 使用方法

### Python 推理

```python
import torch
from torchvision import transforms, models
from PIL import Image
import torch.nn as nn

class CatDogNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.backbone = models.resnet18(weights=None)
        self.backbone.fc = nn.Linear(512, 2)
    
    def forward(self, x):
        return self.backbone(x)

# 加载模型
model = CatDogNet()
model.load_state_dict(torch.load('cat_dog_model.pth', map_location='cpu', weights_only=True))
model.eval()

# 预处理
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

# 预测
img = Image.open('test.jpg').convert('RGB')
img_tensor = transform(img).unsqueeze(0)

with torch.no_grad():
    output = model(img_tensor)
    probs = torch.nn.functional.softmax(output, dim=1)

class_names = ['Cat', 'Dog']
pred_class = class_names[probs.argmax().item()]
print(f'预测类别: {pred_class}')
```

### GGUF 格式加载

```python
from gguf_inference import GGUFLoader, ResNet18Inference

# 加载 GGUF 模型
loader = GGUFLoader('cat_dog_classifier_gpu.gguf')
weights = loader.get_weights()

# 创建推理引擎
engine = ResNet18Inference(weights)

# 预测
import numpy as np
from PIL import Image

img = Image.open('test.jpg').convert('RGB')
img = img.resize((224, 224))
img_array = np.array(img, dtype=np.float32) / 255.0
img_array = (img_array - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]
img_array = img_array.transpose(2, 0, 1)[np.newaxis, ...]

output = engine.forward(img_array)
pred_class = ['Cat', 'Dog'][output.argmax().item()]
```

## 模型文件

- `cat_dog_classifier_gpu.gguf` - GGUF 格式模型 (42.64 MB)
- `cat_dog_model.pth` - PyTorch 权重文件
- `gguf_inference_pytorch.py` - Python 推理脚本

## 训练参数

- Epochs: 15
- Batch size: 64
- Learning rate: 0.0005
- Optimizer: Adam
- Scheduler: StepLR (step_size=3, gamma=0.5)

## 训练过程可视化

### 训练汇总图

![训练汇总](training_summary.png)

### 详细图表

#### 1. 准确率对比
![准确率对比](accuracy_comparison.png)

#### 2. 损失变化曲线
![损失变化](loss_curve.png)

#### 3. 稳定性分析
![稳定性分析](stability_analysis.png)

### 训练统计

| 指标 | 值 |
|------|------|
| 最佳验证准确率 | 98.74% (Epoch 11) |
| 最终训练准确率 | 98.98% |
| 最终验证准确率 | 98.64% |
| 训练损失 | 0.0185 |
| 验证损失 | 0.0512 |
| 波动范围 | ±0.2% (几乎无波动) |

## 许可证

MIT License
