MichalMlodawski commited on
Commit
771020b
1 Parent(s): 5a2d9e4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +125 -1
README.md CHANGED
@@ -7,4 +7,128 @@ language:
7
  tags:
8
  - eye
9
  - eyes
10
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  tags:
8
  - eye
9
  - eyes
10
+ model-index:
11
+ - name: focalnet-base Eye State Classifier
12
+ results:
13
+ - task:
14
+ type: image-classification
15
+ dataset:
16
+ name: MichalMlodawski/closed-open-eyes
17
+ type: custom
18
+ metrics:
19
+ - name: Accuracy
20
+ type: self-reported
21
+ value: 99%
22
+ - name: Precision
23
+ type: self-reported
24
+ value: 99%
25
+ - name: Recall
26
+ type: self-reported
27
+ value: 99%
28
+ ---
29
+ ---
30
+
31
+ # 👁️ Open-Closed Eye Classification FocalNet Base 👁️
32
+
33
+ ## Model Overview 🔍
34
+
35
+ This model is a fine-tuned version of FocalNet-base, specifically designed for classifying images of eyes as either open or closed. With an impressive accuracy of 99%, this classifier excels in distinguishing between open and closed eyes in various contexts.
36
+
37
+ ## Model Details 📊
38
+
39
+ - **Model Name**: open-closed-eye-classification-focalnet-base
40
+ - **Base Model**: FocalNet-base
41
+ - **Fine-tuned By**: Michał Młodawski
42
+ - **Categories**:
43
+ - 0: Closed Eyes 😴
44
+ - 1: Open Eyes 👀
45
+ - **Accuracy**: 99% 🎯
46
+
47
+ ## Use Cases 💡
48
+
49
+ This high-accuracy model is particularly useful for applications involving:
50
+
51
+ - Driver Drowsiness Detection 🚗
52
+ - Attentiveness Monitoring in Educational Settings 🏫
53
+ - Medical Diagnostics related to Eye Conditions 🏥
54
+ - Facial Analysis in Photography and Videography 📸
55
+ - Human-Computer Interaction Systems 💻
56
+
57
+ ## How It Works 🛠️
58
+
59
+ The model takes an input image and classifies it into one of two categories:
60
+
61
+ - **Closed Eyes** (0): Images where the subject's eyes are fully or mostly closed.
62
+ - **Open Eyes** (1): Images where the subject's eyes are open.
63
+
64
+ The classification leverages the advanced image processing capabilities of the FocalNet architecture, fine-tuned on a carefully curated dataset of eye images.
65
+
66
+ ## Getting Started 🚀
67
+
68
+ To start using the open-closed-eye-classification-focalnet-base, you can integrate it into your projects with the following steps:
69
+
70
+ ### Installation
71
+
72
+ ```bash
73
+ pip install transformers==4.37.2
74
+ pip install torch==2.3.1
75
+ pip install Pillow
76
+ ```
77
+
78
+ ### Usage
79
+
80
+ ```python
81
+ import os
82
+ from PIL import Image
83
+ import torch
84
+ from torchvision import transforms
85
+ from transformers import AutoImageProcessor, FocalNetForImageClassification
86
+ import requests
87
+ from io import BytesIO
88
+
89
+ def classify_images(image_folder, model_url):
90
+ jpg_files = [file for file in os.listdir(image_folder) if file.lower().endswith(".jpg")]
91
+
92
+ if not jpg_files:
93
+ print("No files in directory:", image_folder)
94
+ return
95
+
96
+ image_processor = AutoImageProcessor.from_pretrained(model_url)
97
+ model = FocalNetForImageClassification.from_pretrained(model_url)
98
+ model.eval()
99
+
100
+ transform = transforms.Compose([
101
+ transforms.Resize((224, 224)),
102
+ transforms.ToTensor(),
103
+ transforms.Normalize(mean=image_processor.image_mean, std=image_processor.image_std)
104
+ ])
105
+
106
+ results = []
107
+ for jpg_file in jpg_files:
108
+ selected_image = os.path.join(image_folder, jpg_file)
109
+ image = Image.open(selected_image).convert("RGB")
110
+ image_tensor = transform(image).unsqueeze(0)
111
+
112
+ with torch.no_grad():
113
+ outputs = model(image_tensor)
114
+ probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
115
+ confidence, predicted = torch.max(probabilities, 1)
116
+
117
+ results.append((jpg_file, predicted.item(), confidence.item() * 100))
118
+
119
+ for jpg_file, prediction, confidence in results:
120
+ print(f"Filename: {jpg_file}, Prediction: {prediction}, Confidence: {confidence:.2f}%")
121
+
122
+ if __name__ == "__main__":
123
+ image_folder = "#patch_to_images"
124
+ model_url = "https://huggingface.co/MichalMlodawski/open-closed-eye-classification-focalnet-base"
125
+ classify_images(image_folder, model_url)
126
+ ```
127
+
128
+ ## Disclaimer ⚠️
129
+
130
+ This model is provided for research and development purposes only. The creators and distributors of this model do not assume any legal responsibility for its use or misuse. Users are solely responsible for ensuring that their use of this model complies with applicable laws, regulations, and ethical standards. The model's performance may vary depending on the quality and nature of input images. Always validate results in critical applications.
131
+
132
+ 🚫 Do not use this model for any illegal, unethical, or potentially harmful purposes.
133
+
134
+ 📝 Please note that while the model demonstrates high accuracy, it should not be used as a sole decision-making tool in safety-critical systems without proper validation and human oversight.