junler commited on
Commit
9fd72fb
·
verified ·
1 Parent(s): e63552f

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +150 -0
  2. features.json +31 -0
  3. model-card.md +36 -0
README.md ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SimpleConvNetLite: 轻量级CIFAR-10图像分类模型
2
+
3
+ 这是一个为快速训练和部署而设计的轻量级卷积神经网络模型,在CIFAR-10数据集的子集上训练,可以在CPU上10分钟内完成训练。
4
+
5
+ ## 模型描述
6
+
7
+ SimpleConvNetLite是一个简化版的CNN模型,专为快速训练和部署而设计。模型架构简单,参数量小,可以在资源受限的环境中运行。
8
+
9
+ ### 模型架构
10
+
11
+ ```
12
+ SimpleConvNetLite(
13
+ (conv1): Conv2d(3, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
14
+ (pool): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
15
+ (fc1): Linear(in_features=4096, out_features=64, bias=True)
16
+ (fc2): Linear(in_features=64, out_features=10, bias=True)
17
+ )
18
+ ```
19
+
20
+ - 1个卷积层(16个过滤器,3x3卷积核)
21
+ - 1个最大池化层
22
+ - 2个全连接层(64个隐藏单元)
23
+
24
+ 参数总量: ~260K
25
+
26
+ ## 训练数据
27
+
28
+ 模型在CIFAR-10数据集的子集上进行训练:
29
+
30
+ - 只使用原始CIFAR-10数据集的**20%**
31
+ - 训练样本: 10,000张图像(原50,000的20%)
32
+ - 测试样本: 2,000张图像(原10,000的20%)
33
+ - 图像尺寸: 32x32像素,RGB 3通道
34
+ - 类别: 飞机、汽车、鸟、猫、鹿、狗、青蛙、马、船、卡车
35
+
36
+ ## 训练过程
37
+
38
+ - **优化器**: Adam (lr=0.001)
39
+ - **批次大小**: 128
40
+ - **训练轮次**: 2
41
+ - **损失函数**: CrossEntropyLoss
42
+ - **数据预处理**:
43
+ - 调整尺寸到32x32
44
+ - 标准化 (均值=[0.5, 0.5, 0.5], 标准差=[0.5, 0.5, 0.5])
45
+
46
+ ## 训练时长
47
+
48
+ - **CPU (Intel i5或同等配置)**: 约5-10分钟
49
+ - **CPU (Intel i7或同等配置)**: 约3-5分钟
50
+ - **GPU (任何配置)**: 不到1分钟
51
+
52
+ ## 性能指标
53
+
54
+ 在CIFAR-10测试集子集上的准确率约为**50-55%**。
55
+
56
+ ## 使用方法
57
+
58
+ ### 使用Transformers库
59
+
60
+ ```python
61
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
62
+ from PIL import Image
63
+
64
+ # 加载模型和处理器
65
+ processor = AutoImageProcessor.from_pretrained("你的用户名/simple-cnn-cifar10-lite")
66
+ model = AutoModelForImageClassification.from_pretrained("你的用户名/simple-cnn-cifar10-lite")
67
+
68
+ # 加载图像并进行预处理
69
+ image = Image.open("path_to_image.jpg")
70
+ inputs = processor(images=image, return_tensors="pt")
71
+
72
+ # 预测
73
+ outputs = model(**inputs)
74
+ predicted_class_idx = outputs.logits.argmax(-1).item()
75
+ print(f"预测类别: {model.config.id2label[predicted_class_idx]}")
76
+ ```
77
+
78
+ ### 使用PyTorch
79
+
80
+ ```python
81
+ import torch
82
+ from PIL import Image
83
+ import torchvision.transforms as transforms
84
+
85
+ # 定义模型结构
86
+ class SimpleConvNetLite(torch.nn.Module):
87
+ def __init__(self, num_classes=10):
88
+ super(SimpleConvNetLite, self).__init__()
89
+ self.conv1 = torch.nn.Conv2d(3, 16, 3, padding=1)
90
+ self.pool = torch.nn.MaxPool2d(2, 2)
91
+ self.fc1 = torch.nn.Linear(16 * 16 * 16, 64)
92
+ self.fc2 = torch.nn.Linear(64, num_classes)
93
+
94
+ def forward(self, x):
95
+ x = self.pool(torch.nn.functional.relu(self.conv1(x)))
96
+ x = x.view(-1, 16 * 16 * 16)
97
+ x = torch.nn.functional.relu(self.fc1(x))
98
+ x = self.fc2(x)
99
+ return x
100
+
101
+ # 加载模型
102
+ model = SimpleConvNetLite()
103
+ model.load_state_dict(torch.load("pytorch_model.bin", map_location=torch.device('cpu')))
104
+ model.eval()
105
+
106
+ # 图像预处理
107
+ transform = transforms.Compose([
108
+ transforms.Resize((32, 32)),
109
+ transforms.ToTensor(),
110
+ transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
111
+ ])
112
+
113
+ # 类别映射
114
+ classes = ('飞机', '汽车', '鸟', '猫', '鹿', '狗', '青蛙', '马', '船', '卡车')
115
+
116
+ # 加载图像并预测
117
+ image = Image.open("path_to_image.jpg").convert('RGB')
118
+ image_tensor = transform(image).unsqueeze(0)
119
+ with torch.no_grad():
120
+ outputs = model(image_tensor)
121
+ _, predicted = torch.max(outputs, 1)
122
+ print(f"预测类别: {classes[predicted.item()]}")
123
+ ```
124
+
125
+ ## 优势和局限性
126
+
127
+ ### 优势
128
+
129
+ - **快速训练**: 在CPU上可在10分钟内完成训练
130
+ - **轻量级**: 模型体积小,适合部署在资源受限的环境
131
+ - **易于理解**: 简单的架构设计,适合学习和教学目的
132
+
133
+ ### 局限性
134
+
135
+ - **准确率较低**: 相比完整模型,精简版准确率约为50-55%
136
+ - **特征提取能力有限**: 只有一个卷积层,特征提取能力有限
137
+ - **仅用于演示**: 主要用于快速演示和教学,不适合生产环境
138
+
139
+ ## 项目链接
140
+
141
+ - 项目代码: [GitHub仓库链接]
142
+ - Hugging Face Space演示: [你的用户名/simple-cnn-cifar10-lite-demo]
143
+
144
+ ## 许可证
145
+
146
+ MIT
147
+
148
+ ---
149
+
150
+ *本模型由[您的名字]创建,用于Hugging Face学习和演示目的。*
features.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "features": {
3
+ "pixel_values": {
4
+ "feature_extractor_type": "AutoImageProcessor",
5
+ "_type": "Value",
6
+ "dtype": "float32",
7
+ "shape": [
8
+ 3,
9
+ 32,
10
+ 32
11
+ ]
12
+ },
13
+ "labels": {
14
+ "_type": "ClassLabel",
15
+ "names": [
16
+ "飞机",
17
+ "汽车",
18
+ "鸟",
19
+ "猫",
20
+ "鹿",
21
+ "狗",
22
+ "青蛙",
23
+ "马",
24
+ "船",
25
+ "卡车"
26
+ ],
27
+ "names_file": null,
28
+ "id": null
29
+ }
30
+ }
31
+ }
model-card.md ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ - en
5
+ license: mit
6
+ library_name: pytorch
7
+ tags:
8
+ - image-classification
9
+ - cifar10
10
+ - cnn
11
+ - lite-model
12
+ - educational
13
+ datasets:
14
+ - cifar10
15
+ metrics:
16
+ - accuracy
17
+ model-index:
18
+ - name: SimpleConvNetLite
19
+ results:
20
+ - task:
21
+ type: image-classification
22
+ name: Image Classification
23
+ dataset:
24
+ name: CIFAR-10 (20% subset)
25
+ type: cifar10
26
+ metrics:
27
+ - name: Accuracy
28
+ type: accuracy
29
+ value: 0.52
30
+ ---
31
+
32
+ # SimpleConvNetLite模型卡
33
+
34
+ 这是一个轻量级图像分类模型,专为快速训练和部署而设计,可以在CPU上10分钟内完成训练。
35
+
36
+ [完整模型卡请见README.md]