Views
No views yet
| Class | Precision | Recall | F1-Score |
|---|---|---|---|
| Signature | 0.849 | 0.992 | 0.915 |
| Stamp | 1.000 | 0.695 | 0.820 |
| Thumb | 0.922 | 0.913 | 0.917 |
pip install -r requirements.txt1from huggingface_hub import hf_hub_download, HfApi
2import torch
3import torch.nn as nn
4from torchvision import models, transforms
5from PIL import Image
6import torch.nn.functional as F
7
8repo_id = "Ooredoo-Group/stamp-thumb-signature-classifier-resnet18"
9
10# Access via API first (helps with download tracking)
11api = HfApi()
12api.model_info(repo_id)
13
14# Download model
15model_path = hf_hub_download(
16 repo_id=repo_id,
17 filename="pytorch_model.bin"
18)
19
20# Load model
21device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
22state_dict = torch.load(model_path, map_location=device)
23model = models.resnet18(weights=None)
24model.fc = nn.Linear(model.fc.in_features, 3)
25model.load_state_dict(state_dict)
26model.to(device)
27model.eval()
28
29class_names = ["signature", "stamp", "thumb"]1# Preprocess image
2transform = transforms.Compose([
3 transforms.Resize((224, 224)),
4 transforms.ToTensor(),
5])
6image = Image.open("your_image.jpg").convert("RGB")
7input_tensor = transform(image).unsqueeze(0).to(device)
8
9# Predict
10with torch.no_grad():
11 output = model(input_tensor)
12 probabilities = F.softmax(output, dim=1)
13 top_prob, top_idx = torch.max(probabilities, dim=1)
14
15result = {
16 "label": class_names[top_idx.item()],
17 "confidence": top_prob.item(),
18 "probabilities": {
19 class_names[i]: float(probabilities[0][i].item())
20 for i in range(len(class_names))
21 }
22}
23
24print(f"Predicted: {result['label']} (confidence: {result['confidence']:.3f})")example_usage.py.1@misc{stamp-thumb-signature-classifier-resnet18,
2 title={Stamp, Thumb, and Signature Classifier (ResNet18)},
3 author={Ooredoo-Group},
4 year={2024},
5 howpublished={\url{https://huggingface.co/Ooredoo-Group/stamp-thumb-signature-classifier-resnet18}}
6}