Downloads · 30 days
11
8% of all-time downloads
Akimotorakiyu/GuoJing-model
GuoJing-model is a image classification model from Akimotorakiyu. Use it when you need a label for an image. It is set up for transformers. The card lists the license as mit.
这是一个基于CNN的MNIST手写数字识别模型,名为"郭靖"。模型使用PyTorch实现,并与Hugging Face Transformers生态系统完全兼容。
Downloads · 30 days
11
8% of all-time downloads
All-time downloads
146
Public
Parameters
1.7M
6.7 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors6.7 MB · 100%
From the Hugging Face model README
这是一个基于CNN的MNIST手写数字识别模型,名为"郭靖"。模型使用PyTorch实现,并与Hugging Face Transformers生态系统完全兼容。
from transformers import AutoModelForImageClassification, AutoImageProcessor
from PIL import Image
import torch
# 加载模型和处理器
model = AutoModelForImageClassification.from_pretrained("Akimotorakiyu/GuoJing-model")
processor = AutoImageProcessor.from_pretrained("Akimotorakiyu/GuoJing-model")
# 加载并预处理图像
image = Image.open("path/to/your/image.png").convert("L") # 转换为灰度图
inputs = processor(images=image, return_tensors="pt")
# 推理
with torch.no_grad():
outputs = model(**inputs)
predicted_class = outputs.logits.argmax(-1).item()
print(f"Predicted digit: {predicted_class}")
import torch
from torchvision import datasets, transforms
from transformers import AutoModelForImageClassification
# 加载模型
model = AutoModelForImageClassification.from_pretrained("Akimotorakiyu/GuoJing-model")
model.eval()
# 数据预处理
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])
# 加载测试数据
test_dataset = datasets.MNIST(root='./data', train=False, download=True, transform=transform)
test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=32)
# 评估
correct = 0
total = 0
with torch.no_grad():
for images, labels in test_loader:
outputs = model(pixel_values=images)
_, predicted = torch.max(outputs.logits, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
print(f'Test Accuracy: {100 * correct / total:.2f}%')
{
"conv_channels": [32, 64],
"conv_kernel_size": 3,
"conv_padding": 1,
"pool_kernel_size": 2,
"pool_stride": 2,
"conv_dropout": 0.25,
"fc_dropout": 0.5,
"hidden_size": 512,
"input_channels": 1,
"num_classes": 10,
"image_size": 28,
"normalize_mean": 0.1307,
"normalize_std": 0.3081
}
ToTensor(): 将PIL图像转换为张量Normalize((0.1307,), (0.3081,)): MNIST标准化值pytorch_model.bin: 训练好的模型权重config.json: 模型配置文件preprocessor_config.json: 图像预处理配置MIT License
Akimotorakiyu
注意: 这是一个名为"郭靖"的MNIST分类模型,以纪念这位武侠小说中的传奇人物,象征着模型的稳健和可靠。