Shanmukhcr7 commited on
Commit
aa72e25
·
verified ·
1 Parent(s): 7bc725d

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +71 -1
README.md CHANGED
@@ -1,3 +1,73 @@
1
  ---
2
- license: apache-2.0
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ license: mit
5
+ tags:
6
+ - vision
7
+ - age-detection
8
+ - pytorch
9
+ - resnet18
10
+ - image-classification
11
  ---
12
+
13
+ # Age-X Age Detection Model
14
+
15
+ This is a **ResNet18-based age prediction model** trained to detect and predict the age of a person from a facial image. It is designed with safety and high performance in mind, originally built for the Age-X Next-Generation Age Verification Platform.
16
+
17
+ By open-sourcing this model, we hope to enable developers to build safer, age-aware applications.
18
+
19
+ ## 🚀 Model Details
20
+
21
+ - **Architecture:** ResNet18 (Regression)
22
+ - **Framework:** PyTorch
23
+ - **Task:** Age Estimation
24
+ - **License:** MIT (Open Source)
25
+
26
+ ## 💻 How to use in Python
27
+
28
+ You can download the model weights and use them directly with PyTorch. For best results, use a face detector (like OpenCV) to crop the face first, as shown in the `age_service.py` file included in this repository.
29
+
30
+ Here is a minimal example of how to load the model and run an inference on a cropped face:
31
+
32
+ ```python
33
+ import torch
34
+ import torch.nn as nn
35
+ from torchvision import models, transforms
36
+ from PIL import Image
37
+
38
+ # 1. Initialize the ResNet18 Model
39
+ model = models.resnet18(weights=None)
40
+ model.fc = nn.Linear(model.fc.in_features, 1) # Set output to 1 for age regression
41
+ model.load_state_dict(torch.load("age_model.pth", map_location="cpu"))
42
+ model.eval()
43
+
44
+ # 2. Prepare the Image
45
+ transform = transforms.Compose([
46
+ transforms.Resize((224, 224)),
47
+ transforms.ToTensor(),
48
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
49
+ ])
50
+
51
+ # NOTE: The image should be a tightly cropped face for accurate predictions
52
+ image = Image.open("path_to_cropped_face.jpg").convert("RGB")
53
+ input_tensor = transform(image).unsqueeze(0)
54
+
55
+ # 3. Predict Age
56
+ with torch.no_grad():
57
+ predicted_age = model(input_tensor).item()
58
+
59
+ print(f"Predicted Age: {max(1, min(100, predicted_age)):.1f}")
60
+ ```
61
+
62
+ ## 🏗️ Interactive Demo (Gradio)
63
+
64
+ We have also included an `app.py` built with Gradio! You can deploy this exact repository to **Hugging Face Spaces** (select Gradio as the SDK) to get an instant web UI where you can upload photos and see the prediction.
65
+
66
+ Alternatively, you can run the demo locally:
67
+ ```bash
68
+ pip install -r requirements.txt
69
+ python app.py
70
+ ```
71
+
72
+ ## ⚠️ Limitations & Bias
73
+ This model provides age estimation based on facial features. Results may vary significantly depending on lighting conditions, camera angles, and demographics. It relies on standard ResNet18 architecture which is optimized for general image processing but may exhibit standard biases present in its training dataset. Always use fallback safety mechanisms in production environments.