Jwalit commited on
Commit
48fcf1e
·
verified ·
1 Parent(s): da06da7

Update README with model details and usage instructions

Browse files
Files changed (1) hide show
  1. README.md +65 -3
README.md CHANGED
@@ -1,3 +1,65 @@
1
- # kyc-document-corner-detector
2
- KYC document segmentation | MobileNetV3-Small | CPU trained
3
- Dataset: Jwalit/moire-docs | 8 epochs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # KYC Document Corner Detector
2
+
3
+ Lightweight document segmentation model trained on KYC documents (Aadhaar, PAN, passports, visas) from the `Jwalit/moire-docs` dataset.
4
+
5
+ ## Model Details
6
+
7
+ | Property | Value |
8
+ |----------|-------|
9
+ | Architecture | MobileNetV3-Small encoder + upsampling decoder |
10
+ | Task | Binary segmentation (document vs background) |
11
+ | Training | CPU only, 8 epochs |
12
+ | Images | 461 (391 train, 70 val) |
13
+ | **Best Val IoU** | **74.79%** |
14
+ | Model size | ~10 MB |
15
+ | Labels | Self-supervised via OpenCV contour detection |
16
+
17
+ ## How It Works
18
+
19
+ 1. **Input**: Raw KYC document image (any size)
20
+ 2. **Segmentation**: Model predicts binary mask of document region
21
+ 3. **Corner Detection**: OpenCV contour extraction finds 4 corners from mask
22
+ 4. **Perspective Transform**: Crops to document boundaries
23
+
24
+ ## Self-Supervised Label Generation
25
+
26
+ Labels are generated automatically using classical computer vision:
27
+ - Grayscale → Gaussian blur → Adaptive thresholding
28
+ - Morphological closing connects text regions
29
+ - Largest contour extraction → 4-corner approximation
30
+
31
+ No manual annotation required.
32
+
33
+ ## Files
34
+
35
+ | File | Description |
36
+ |------|-------------|
37
+ | `pytorch_model.bin` | Trained model weights |
38
+ | `config.json` | Model configuration |
39
+ | `inference_pipeline.py` | Complete inference script (crop + rotate) |
40
+ | `train_rotation_classifier.py` | Script to train rotation classifier |
41
+
42
+ ## Usage
43
+
44
+ ```python
45
+ import torch
46
+ from inference_pipeline import SegModel, predict_corners
47
+
48
+ model = SegModel()
49
+ model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
50
+ corners = predict_corners(model, "your_document.jpg")
51
+ ```
52
+
53
+ ## Related Model
54
+
55
+ - **Rotation Classifier**: https://huggingface.co/Jwalit/kyc-document-rotation-classifier
56
+ - 4-class classifier: 0°, 90°, 180°, 270°
57
+ - Run `train_rotation_classifier.py` to train on your CPU
58
+
59
+ ## Pipeline
60
+
61
+ ```
62
+ Raw Image → SegModel → Mask → Contours → 4 Corners → Crop
63
+
64
+ RotModel → Classify Rotation → Correct Orientation
65
+ ```