logasanjeev commited on
Commit
68deb3e
·
verified ·
1 Parent(s): 985700a

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +295 -3
README.md CHANGED
@@ -1,3 +1,295 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ metrics:
6
+ - accuracy
7
+ - recall
8
+ - precision
9
+ - mean_iou
10
+ base_model:
11
+ - Ultralytics/YOLO11
12
+ pipeline_tag: image-to-text
13
+ tags:
14
+ - OCR
15
+ - YOLO
16
+ - Pytorch
17
+ ---
18
+ # Indian ID Validator
19
+
20
+ [![Hugging Face Model](https://img.shields.io/badge/Hugging%20Face-Model-blue)](https://huggingface.co/logasanjeev/indian-id-validator)
21
+
22
+ A robust computer vision pipeline for classifying, detecting, and extracting text from Indian identification documents, including Aadhaar, PAN Card, Passport, Voter ID, and Driving License. Powered by YOLO11 models and PaddleOCR, this project supports both front and back images for Aadhaar and Driving License.
23
+
24
+ ## Overview
25
+
26
+ The **Indian ID Validator** uses deep learning to:
27
+ - **Classify** ID types (e.g., `aadhar_front`, `passport`) with the `Id_Classifier` model.
28
+ - **Detect** specific fields (e.g., Aadhaar Number, DOB, Name) using type-specific YOLO11 detection models.
29
+ - **Extract** text from detected fields via PaddleOCR with image preprocessing (upscaling, denoising, contrast enhancement).
30
+
31
+ Supported ID types:
32
+ - Aadhaar (front and back)
33
+ - PAN Card (front)
34
+ - Passport (front)
35
+ - Voter ID (front and back)
36
+ - Driving License (front and back)
37
+
38
+ ## Models
39
+
40
+ ### Id_Classifier
41
+ - **Model**: YOLO11l-cls
42
+ - **Classes**: `aadhar_back`, `aadhar_front`, `driving_license_back`, `driving_license_front`, `pan_card_front`, `passport`, `voter_id`
43
+ - **Metrics**:
44
+ - Accuracy (Top-1): 0.995
45
+ - Accuracy (Top-5): 1.0
46
+ - **Link**: [Ultralytics Hub](https://hub.ultralytics.com/models/QnJjO78MxBaRVeX2wOO4)
47
+
48
+ ### Aadhaar
49
+ - **Model**: YOLO11l
50
+ - **Classes**: `Aadhaar_Number`, `Aadhaar_DOB`, `Aadhaar_Gender`, `Aadhaar_Name`, `Aadhaar_Address`
51
+ - **Metrics**:
52
+ - mAP50: 0.795
53
+ - mAP50-95: 0.553
54
+ - Precision: 0.777
55
+ - Recall: 0.774
56
+ - Fitness: 0.577
57
+ - **Link**: [Kaggle Notebook](https://www.kaggle.com/code/ravindranlogasanjeev/aadhaar)
58
+
59
+ ### Driving_License
60
+ - **Model**: YOLO11l
61
+ - **Classes**: `Address`, `Blood Group`, `DL No`, `DOB`, `Name`, `Relation With`, `RTO`, `State`, `Vehicle Type`
62
+ - **Metrics**:
63
+ - mAP50: 0.690
64
+ - mAP50-95: 0.524
65
+ - Precision: 0.752
66
+ - Recall: 0.669
67
+ - **Link**: [Ultralytics Hub](https://hub.ultralytics.com/models/eaHzQ79umKwJkic9DXbm)
68
+
69
+ ### Pan_Card
70
+ - **Model**: YOLO11l
71
+ - **Classes**: `PAN`, `Name`, `Father's Name`, `DOB`, `Pan Card`
72
+ - **Metrics**:
73
+ - mAP50: 0.924
74
+ - mAP50-95: 0.686
75
+ - Precision: 0.902
76
+ - Recall: 0.901
77
+ - **Link**: [Ultralytics Hub](https://hub.ultralytics.com/models/Yj4aJ34fK02MkrHFSXq0)
78
+
79
+ ### Passport
80
+ - **Model**: YOLO11l
81
+ - **Classes**: `Address`, `Code`, `DOB`, `DOI`, `EXP`, `Gender`, `MRZ1`, `MRZ2`, `Name`, `Nationality`, `Nation`, `POI`
82
+ - **Metrics**:
83
+ - mAP50: 0.987
84
+ - mAP50-95: 0.851
85
+ - Precision: 0.972
86
+ - Recall: 0.967
87
+ - **Link**: [Ultralytics Hub](https://hub.ultralytics.com/models/ELaiHGZ0bbr4JwsvSZ7z)
88
+
89
+ ### Voter_Id
90
+ - **Model**: YOLO11l
91
+ - **Classes**: `Address`, `Age`, `DOB`, `Card Voter ID 1 Back`, `Card Voter ID 2 Front`, `Card Voter ID 2 Back`, `Card Voter ID 1 Front`, `Date of Issue`, `Election`, `Father`, `Gender`, `Name`, `Point`, `Portrait`, `Symbol`, `Voter ID`
92
+ - **Metrics**:
93
+ - mAP50: 0.917
94
+ - mAP50-95: 0.772
95
+ - Precision: 0.922
96
+ - Recall: 0.873
97
+ - **Link**: [Ultralytics Hub](https://hub.ultralytics.com/models/jAz7y1UQAfr2oBlwLGDp)
98
+
99
+ ## Installation
100
+
101
+ 1. **Clone the Repository**:
102
+ ```bash
103
+ git clone https://huggingface.co/logasanjeev/indian-id-validator
104
+ cd indian-id-validator
105
+ ```
106
+
107
+ 2. **Install Dependencies**:
108
+ Ensure Python 3.8+ is installed, then run:
109
+ ```bash
110
+ pip install -r requirements.txt
111
+ ```
112
+ The `requirements.txt` includes `ultralytics`, `paddleocr`, `paddlepaddle`, `numpy==1.24.4`, `pandas==2.2.2`, and others.
113
+
114
+ 3. **Download Models**:
115
+ Models are downloaded automatically via `inference.py` from the Hugging Face repository. Ensure `config.json` is in the root directory.
116
+
117
+ ## Usage
118
+
119
+ ### Python API
120
+
121
+ #### Classification Only
122
+ Use `Id_Classifier` to identify the ID type:
123
+ ```python
124
+ from ultralytics import YOLO
125
+ import cv2
126
+
127
+ # Load model
128
+ model = YOLO("models/Id_Classifier.pt")
129
+
130
+ # Load image
131
+ image = cv2.imread("samples/aadhaar_front.jpg")
132
+
133
+ # Classify
134
+ results = model(image)
135
+
136
+ # Print predicted class and confidence
137
+ for result in results:
138
+ predicted_class = result.names[result.probs.top1]
139
+ confidence = result.probs.top1conf.item()
140
+ print(f"Predicted Class: {predicted_class}, Confidence: {confidence:.2f}")
141
+ ```
142
+ **Output**:
143
+ ```
144
+ Predicted Class: aadhar_front, Confidence: 1.00
145
+ ```
146
+
147
+ #### End-to-End Processing
148
+ Use `inference.py` for classification, detection, and OCR:
149
+ ```python
150
+ from inference import process_id
151
+
152
+ # Process an Aadhaar back image
153
+ result = process_id(
154
+ image_path="samples/aadhaar_back.jpg",
155
+ save_json=True,
156
+ output_json="detected_aadhaar_back.json",
157
+ verbose=True
158
+ )
159
+
160
+ # Print results
161
+ import json
162
+ print(json.dumps(result, indent=2))
163
+ ```
164
+ **Output**:
165
+ ```json
166
+ {
167
+ "Aadhaar": "996269466937",
168
+ "Address": "S/O Gocala Shinde Jay Bnavani Rahiwasi Seva Sangh ..."
169
+ }
170
+ ```
171
+
172
+ #### Processing a Passport with Visualizations
173
+ Process a passport image to classify, detect fields, and extract text, with visualizations enabled:
174
+ ```python
175
+ from inference import process_id
176
+
177
+ # Process a passport image with verbose output
178
+ result = process_id(
179
+ image_path="samples/passport_front.jpg",
180
+ save_json=True,
181
+ output_json="detected_passport.json",
182
+ verbose=True
183
+ )
184
+
185
+ # Print results
186
+ import json
187
+ print("\nPassport Results:")
188
+ print(json.dumps(result, indent=4))
189
+ ```
190
+
191
+ **Visualizations**:
192
+ The `verbose=True` flag generates visualizations for the raw image, bounding boxes, and each detected field with extracted text. Below are the results for `passport_front.jpg`:
193
+
194
+ - **Raw Image**:
195
+ ![Raw Image](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_raw_image.png)
196
+
197
+ - **Output with Bounding Boxes**:
198
+ ![Output with Bounding Boxes](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_output_bboxes.png)
199
+
200
+ - **Detected Fields**:
201
+ - **Address**:
202
+ ![Address](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_Address.png)
203
+ - **Code**:
204
+ ![Code](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_Code.png)
205
+ - **DOB**:
206
+ ![DOB](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_DOB.png)
207
+ - **DOI**:
208
+ ![DOI](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_DOI.png)
209
+ - **EXP**:
210
+ ![EXP](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_EXP.png)
211
+ - **Gender**:
212
+ ![Gender](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_Gender.png)
213
+ - **MRZ1**:
214
+ ![MRZ1](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_MRZ1.png)
215
+ - **MRZ2**:
216
+ ![MRZ2](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_MRZ2.png)
217
+ - **Name**:
218
+ ![Name](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_Name.png)
219
+ - **Nationality**:
220
+ ![Nationality](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_Nationality.png)
221
+ - **Nation**:
222
+ ![Nation](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_Nation.png)
223
+ - **POI**:
224
+ ![POI](https://huggingface.co/logasanjeev/indian-id-validator/raw/main/results/passport_POI.png)
225
+
226
+ **Output**:
227
+ ```
228
+ Passport Results:
229
+ {
230
+ "Nation": "INDIAN",
231
+ "DOB": "26/08/1996",
232
+ "POI": "AMRITSAR",
233
+ "DOI": "18/06/2015",
234
+ "Code": "NO461879",
235
+ "EXP": "17/06/2025",
236
+ "Address": "SHER SINGH WALAFARIDKOTASPUNJAB",
237
+ "Name": "SHAMINDERKAUR",
238
+ "Nationality": "IND",
239
+ "Gender": "F",
240
+ "MRZ1": "P<INDSANDHU<<SHAMINDER<KAUR<<<<<<<<<<<<<<<<<",
241
+ "MRZ2": "NO461879<4IND9608269F2506171<<<<<<<<<<<<<<<2"
242
+ }
243
+ ```
244
+
245
+ ### Terminal
246
+ Run `inference.py` via the command line:
247
+ ```bash
248
+ python inference.py samples/aadhaar_front.jpg --verbose --output-json detected_aadhaar.json
249
+ ```
250
+ **Options**:
251
+ - `--model`: Specify model (e.g., `Aadhaar`, `Passport`). Default: auto-detect.
252
+ - `--no-save-json`: Disable JSON output.
253
+ - `--verbose`: Show visualizations.
254
+ - `--classify-only`: Only classify ID type.
255
+
256
+ **Example Output**:
257
+ ```
258
+ Detected document type: aadhar_front with confidence: 0.98
259
+ Extracted Text:
260
+ {
261
+ "Aadhaar": "1234 5678 9012",
262
+ "DOB": "01/01/1990",
263
+ "Gender": "M",
264
+ "Name": "John Doe",
265
+ "Address": "123 Main St, City, State"
266
+ }
267
+ ```
268
+
269
+ ## Colab Tutorial
270
+
271
+ Try the interactive tutorial to test the model with sample images or your own:
272
+ [Open in Colab](https://colab.research.google.com/drive/1_hIvuJ9p1kx8wKTG1ThK9vV8ijiNTlPX)
273
+
274
+ ## Links
275
+
276
+ - **Repository**: [Hugging Face](https://huggingface.co/logasanjeev/indian-id-validator)
277
+ - **Models**:
278
+ - Id_Classifier: [Ultralytics](https://hub.ultralytics.com/models/QnJjO78MxBaRVeX2wOO4)
279
+ - Aadhaar: [Kaggle](https://www.kaggle.com/code/ravindranlogasanjeev/aadhaar)
280
+ - Pan_Card: [Ultralytics](https://hub.ultralytics.com/models/Yj4aJ34fK02MkrHFSXq0)
281
+ - Passport: [Ultralytics](https://hub.ultralytics.com/models/ELaiHGZ0bbr4JwsvSZ7z)
282
+ - Voter_Id: [Ultralytics](https://hub.ultralytics.com/models/jAz7y1UQAfr2oBlwLGDp)
283
+ - Driving_License: [Ultralytics](https://hub.ultralytics.com/models/eaHzQ79umKwJkic9DXbm)
284
+ - **Tutorial**: [Colab Notebook](https://colab.research.google.com/drive/1_hIvuJ9p1kx8wKTG1ThK9vV8ijiNTlPX)
285
+ - **Inference Script**: [inference.py](https://huggingface.co/logasanjeev/indian-id-validator/blob/main/inference.py)
286
+ - **Config**: [config.json](https://huggingface.co/logasanjeev/indian-id-validator/blob/main/config.json)
287
+
288
+ ## Contributing
289
+
290
+ Contributions are welcome! To contribute:
291
+ 1. Fork the repository.
292
+ 2. Create a branch: `git checkout -b feature-name`.
293
+ 3. Submit a pull request with your changes.
294
+
295
+ Report issues or suggest features via the [Hugging Face Issues](https://huggingface.co/logasanjeev/indian-id-validator/discussions) page.