File size: 2,191 Bytes
964c482
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
tags:
- image-classification
- pytorch
- computer-vision
- lanyard-detection
- sdg-16
license: mit
datasets:
- custom
metrics:
- accuracy
library_name: pytorch
---

# Lanyard Detector - School Safety AI

This model detects whether a person is wearing a lanyard/ID badge around their neck.

## ๐ŸŽฏ Use Case

**Problem:** Manual lanyard checking at school entrances is time-consuming.

**Solution:** Automated computer vision system for real-time lanyard detection.

**SDG Impact:** SDG 16 (Peace, Justice & Strong Institutions) - School safety

## ๐Ÿ“Š Model Details

- **Architecture:** MobileNetV2 (Transfer Learning)
- **Input:** RGB images (224x224)
- **Output:** Binary classification
  - Class 0: `has_lanyard`
  - Class 1: `no_lanyard`
- **Framework:** PyTorch

## ๐Ÿš€ Quick Start

```python
import torch
from torchvision import transforms, models
from PIL import Image

# Load model
checkpoint = torch.load('pytorch_model.pth', map_location='cpu')
model = models.mobilenet_v2()
model.classifier[1] = torch.nn.Linear(1280, 2)
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()

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

# Predict
img = Image.open('test.jpg')
img_tensor = transform(img).unsqueeze(0)

with torch.no_grad():
    output = model(img_tensor)
    probs = torch.softmax(output, dim=1)
    pred_class = output.argmax(1).item()
    
classes = ['has_lanyard', 'no_lanyard']
print(f"Prediction: {classes[pred_class]}")
print(f"Confidence: {probs[0][pred_class]*100:.1f}%")
```

## ๐Ÿ“ Training Details

- Custom dataset with data augmentation
- 70% train / 15% val / 15% test split
- Adam optimizer (lr=0.001)
- 15 epochs

## โšก Deployment

Deploy via:
- Featherless AI (Hugging Face partner)
- ONNX Runtime
- TorchScript
- Edge devices

## โš ๏ธ Limitations

- Best with frontal/slight side angles
- Requires adequate lighting
- May struggle with very small/distant lanyards

## ๐Ÿ“„ License

MIT License

---

**Developed for:** Goals in Code Hackathon 2026  
**SDG:** 16 - Peace, Justice & Strong Institutions