Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
@@ -9,43 +9,121 @@ metrics:
|
|
9 |
tags:
|
10 |
- image-classification
|
11 |
---
|
12 |
-
# Model Description
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
The creators of the dataset wrote the following paper employing CelebA for face detection:
|
23 |
-
S. Yang, P. Luo, C. C. Loy, and X. Tang,
|
24 |
-
"From Facial Parts Responses to Face Detection: A Deep Learning Approach", in IEEE International Conference on Computer Vision (ICCV), 2015.
|
25 |
-
- Language: English
|
26 |
-
- Number of Training Steps: 20
|
27 |
-
- Batch size: 32
|
28 |
-
- Optimizer: Adam
|
29 |
-
- Learning Rate: 0.001
|
30 |
-
- GPU: T4
|
31 |
-
- This repository has the source [code used](https://github.com/Nkluge-correa/teeny-tiny_castle/blob/master/ML%20Fairness/fair_metrics_celeba.ipynb) to train this model.
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
@misc{teenytinycastle,
|
41 |
doi = {10.5281/zenodo.7112065},
|
42 |
-
url = {https://
|
43 |
author = {Nicholas Kluge Corr{\^e}a},
|
44 |
title = {Teeny-Tiny Castle},
|
45 |
-
year = {
|
46 |
-
publisher = {
|
47 |
-
journal = {
|
48 |
}
|
49 |
```
|
|
|
50 |
## License
|
51 |
-
|
|
|
|
|
|
9 |
tags:
|
10 |
- image-classification
|
11 |
---
|
|
|
12 |
|
13 |
+
# LeNNon-Smile-Detector
|
14 |
|
15 |
+
## Model Overview
|
16 |
|
17 |
+
The LeNNon-Smile-Detector is a convolutional neural network trained to detect the presence of a human smile in a facial image.
|
18 |
|
19 |
+
### Details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
- **Size:** 2,566,506 parameters
|
22 |
+
- **Model type:** Convolutional neural network
|
23 |
+
- **Optimizer**: `torch.optim.Adam` with a learning rate of 0.001
|
24 |
+
- **Number of Epochs:** 20
|
25 |
+
- **Batch Size:** 256
|
26 |
+
- **Hardware:** Tesla V4
|
27 |
+
- **Emissions:** Not measured
|
28 |
+
- **Total Energy Consumption:** Not measured
|
29 |
|
30 |
+
### How to Use
|
31 |
|
32 |
+
```python
|
33 |
+
import torch
|
34 |
+
from PIL import Image
|
35 |
+
from lennon import LeNNon
|
36 |
+
from torchvision import transforms
|
37 |
+
from huggingface_hub import hf_hub_download
|
38 |
|
39 |
+
# Download the pytorch model
|
40 |
+
hf_hub_download(repo_id="AiresPucrs/LeNNon-Smile-Detector",
|
41 |
+
filename="LeNNon-Smile-Detector.pt",
|
42 |
+
local_dir="./",
|
43 |
+
repo_type="model"
|
44 |
+
)
|
45 |
+
|
46 |
+
# Download the source implementation of the model's architecture
|
47 |
+
hf_hub_download(repo_id="AiresPucrs/LeNNon-Smile-Detector",
|
48 |
+
filename="lennon.py",
|
49 |
+
local_dir="./",
|
50 |
+
repo_type="model"
|
51 |
+
)
|
52 |
+
|
53 |
+
# Check if GPU is available
|
54 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
55 |
+
|
56 |
+
# Load the model an pass it to the proper device
|
57 |
+
model = torch.load('./LeNNon-Smile-Detector.pt')
|
58 |
+
model = model.to(device)
|
59 |
+
model.eval()
|
60 |
+
|
61 |
+
# This `transform` object will transform our test images into proper tensors
|
62 |
+
transform = transforms.Compose([
|
63 |
+
transforms.Resize((100, 100)), # Resize the image to 100x100
|
64 |
+
transforms.ToTensor(),
|
65 |
+
])
|
66 |
+
|
67 |
+
image_path = "your_image_path_here"
|
68 |
+
|
69 |
+
# Open and preprocess he image
|
70 |
+
image = Image.open(image_path)
|
71 |
+
tensor = transform(image)
|
72 |
+
tensor = tensor.to(device)
|
73 |
+
|
74 |
+
# forward pass trough the model
|
75 |
+
with torch.no_grad():
|
76 |
+
|
77 |
+
outputs = model(tensor)
|
78 |
+
|
79 |
+
# Get the class prediction
|
80 |
+
_, predicted = torch.max(outputs.data, 1)
|
81 |
+
|
82 |
+
print("Smiling" if predicted.item() > 0 else "Not Smiling")
|
83 |
```
|
84 |
+
|
85 |
+
## Intended Use
|
86 |
+
|
87 |
+
This model was created for research purposes only. Specifically, it was designed to explore discriminatory biases present in a subset of the CelebA dataset (the [CelebA-Smiles](https://huggingface.co/datasets/AiresPucrs/CelebA-Smiles)). We do not recommend any application of this model outside this scope.
|
88 |
+
|
89 |
+
|
90 |
+
## Performance Metrics
|
91 |
+
|
92 |
+
The model achieved an accuracy of 97% in a test set split containing 5000 images from the [CelebA-Smiles](https://huggingface.co/datasets/AiresPucrs/CelebA-Smiles).
|
93 |
+
|
94 |
+
## Training Data
|
95 |
+
|
96 |
+
The model was trained on a subset of the [CelebA dataset](https://www.kaggle.com/datasets/jessicali9530/celeba-dataset), i.e., CelebA-Smiles.
|
97 |
+
|
98 |
+
CelebA-Smiles contains 50K images. 25K of smiling faces, and 25K of non smiling faces.
|
99 |
+
|
100 |
+
Images on the CelebA-Smiles were resized to 100 x 100 pixels before training the model. For more details on the features contained in the CelebA-Smiles dataset, check its [dataset card](https://huggingface.co/datasets/AiresPucrs/CelebA-Smiles).
|
101 |
+
|
102 |
+
## Limitations
|
103 |
+
|
104 |
+
We performed a simple fairness analysis of our model regarding the sensitive attribute **age**.
|
105 |
+
|
106 |
+
According to our analysis, the model has no discriminatory bias regarding this feature. Results can be found [here](https://github.com/Nkluge-correa/teeny-tiny_castle/blob/master/ML%20Fairness/fair_metrics_celeba.ipynb).
|
107 |
+
|
108 |
+
Other possible biases were not investigated, but further investigations are likely given that other sensitive attributes present in the training dataset are available.
|
109 |
+
|
110 |
+
In conclusion, we do not recommend using this model in real-world applications. It was solely developed for academic and educational purposes.
|
111 |
+
|
112 |
+
## Cite as
|
113 |
+
|
114 |
+
```latex
|
115 |
@misc{teenytinycastle,
|
116 |
doi = {10.5281/zenodo.7112065},
|
117 |
+
url = {https://github.com/Nkluge-correa/teeny-tiny_castle},
|
118 |
author = {Nicholas Kluge Corr{\^e}a},
|
119 |
title = {Teeny-Tiny Castle},
|
120 |
+
year = {2024},
|
121 |
+
publisher = {GitHub},
|
122 |
+
journal = {GitHub repository},
|
123 |
}
|
124 |
```
|
125 |
+
|
126 |
## License
|
127 |
+
|
128 |
+
This model is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for more details.
|
129 |
+
|