Jwalit commited on
Commit
d44d8fc
·
verified ·
1 Parent(s): 280b928

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +22 -61
  2. config.json +5 -2
  3. pytorch_model.bin +2 -2
  4. training_history.json +58 -0
README.md CHANGED
@@ -1,77 +1,38 @@
1
- ---
2
- tags:
3
- - ml-intern
4
- ---
5
- # KYC Document Corner Detector
6
 
7
- Lightweight document segmentation model trained on KYC documents (Aadhaar, PAN, passports, visas) from the `Jwalit/moire-docs` dataset.
8
 
9
- ## Model Details
 
 
 
 
 
 
 
10
 
11
- | Property | Value |
12
- |----------|-------|
13
- | Architecture | MobileNetV3-Small encoder + upsampling decoder |
14
- | Task | Binary segmentation (document vs background) |
15
- | Training | CPU only, 8 epochs |
16
- | Images | 461 (391 train, 70 val) |
17
- | **Best Val IoU** | **74.79%** |
18
- | Model size | ~10 MB |
19
- | Labels | Self-supervised via OpenCV contour detection |
20
 
21
- ## How It Works
22
-
23
- 1. **Input**: Raw KYC document image (any size)
24
- 2. **Segmentation**: Model predicts binary mask of document region
25
- 3. **Corner Detection**: OpenCV contour extraction finds 4 corners from mask
26
- 4. **Perspective Transform**: Crops to document boundaries
27
-
28
- ## Self-Supervised Label Generation
29
-
30
- Labels are generated automatically using classical computer vision:
31
- - Grayscale → Gaussian blur → Adaptive thresholding
32
- - Morphological closing connects text regions
33
- - Largest contour extraction → 4-corner approximation
34
-
35
- No manual annotation required.
36
-
37
- ## Files
38
-
39
- | File | Description |
40
- |------|-------------|
41
- | `pytorch_model.bin` | Trained model weights |
42
- | `config.json` | Model configuration |
43
- | `inference_pipeline.py` | Complete inference script (crop + rotate) |
44
- | `train_rotation_classifier.py` | Script to train rotation classifier |
45
 
46
  ## Usage
47
 
48
  ```python
49
  import torch
50
- from inference_pipeline import SegModel, predict_corners
51
 
52
- model = SegModel()
53
  model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
54
- corners = predict_corners(model, "your_document.jpg")
55
  ```
56
 
57
- ## Related Model
58
-
59
- - **Rotation Classifier**: https://huggingface.co/Jwalit/kyc-document-rotation-classifier
60
- - 4-class classifier: 0°, 90°, 180°, 270°
61
- - Run `train_rotation_classifier.py` to train on your CPU
62
-
63
- ## Pipeline
64
-
65
- ```
66
- Raw Image → SegModel → Mask → Contours → 4 Corners → Crop
67
-
68
- RotModel → Classify Rotation → Correct Orientation
69
- ```
70
 
71
- <!-- ml-intern-provenance -->
72
- ## Generated by ML Intern
73
 
74
- This model repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.
75
 
76
- - Try ML Intern: https://smolagents-ml-intern.hf.space
77
- - Source code: https://github.com/huggingface/ml-intern
 
1
+ # kyc-document-corner-detector
 
 
 
 
2
 
3
+ KYC Document Segmentation Model | MobileNetV3-Small | CPU Trained
4
 
5
+ ## Details
6
+ - **Task**: document_segmentation
7
+ - **Backbone**: mobilenet_v3_small
8
+ - **Input size**: 224px
9
+ - **Epochs**: 8
10
+ - **Best metric**: 0.8262 IoU
11
+ - **Dataset**: Jwalit/moire-docs
12
+ - **Total images**: 2623
13
 
14
+ ## Training
 
 
 
 
 
 
 
 
15
 
16
+ This model was trained on CPU using self-supervised labels:
17
+ - **Segmentation**: OpenCV-generated document masks
18
+ - **Rotation**: Synthetically rotated with known angles
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  ## Usage
21
 
22
  ```python
23
  import torch
24
+ from model import YourModelClass # See training script
25
 
26
+ model = YourModelClass()
27
  model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
28
+ model.eval()
29
  ```
30
 
31
+ ## Dataset
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ - Source: `Jwalit/moire-docs`
34
+ - Contains KYC documents with clean and moire (scan artifacts) variants
35
 
36
+ ## License
37
 
38
+ Same as dataset license.
 
config.json CHANGED
@@ -1,6 +1,9 @@
1
  {
2
- "task": "segmentation",
3
  "backbone": "mobilenet_v3_small",
4
  "img_size": 224,
5
- "epochs": 8
 
 
 
6
  }
 
1
  {
2
+ "task": "document_segmentation",
3
  "backbone": "mobilenet_v3_small",
4
  "img_size": 224,
5
+ "epochs": 8,
6
+ "device": "cpu",
7
+ "best_metric": "0.8262 IoU",
8
+ "num_images": 2623
9
  }
pytorch_model.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0c469834f4850e6e69d9e15c783ef85f8d9251f54413b2e78a2e142a372df2b7
3
- size 10718163
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5965be686006a0b869f02cc3dc1f1222fb28d98c89bb8f1dd67e21aa1b1db7d9
3
+ size 10735543
training_history.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "epoch": 1,
4
+ "train_loss": 0.4692644519617908,
5
+ "val_loss": 0.34619138449430464,
6
+ "val_iou": 0.7933830893039704,
7
+ "time_sec": 310.975909948349
8
+ },
9
+ {
10
+ "epoch": 2,
11
+ "train_loss": 0.3308764501711801,
12
+ "val_loss": 0.304664246737957,
13
+ "val_iou": 0.8000004982948303,
14
+ "time_sec": 287.062824010849
15
+ },
16
+ {
17
+ "epoch": 3,
18
+ "train_loss": 0.2706743049365218,
19
+ "val_loss": 0.2952070167660713,
20
+ "val_iou": 0.7954098653793334,
21
+ "time_sec": 283.8040874004364
22
+ },
23
+ {
24
+ "epoch": 4,
25
+ "train_loss": 0.22350290676705725,
26
+ "val_loss": 0.29507764175534246,
27
+ "val_iou": 0.7969379591941833,
28
+ "time_sec": 282.5429263114929
29
+ },
30
+ {
31
+ "epoch": 5,
32
+ "train_loss": 0.1895671994775854,
33
+ "val_loss": 0.2825832884758711,
34
+ "val_iou": 0.8065838325023651,
35
+ "time_sec": 286.93286657333374
36
+ },
37
+ {
38
+ "epoch": 6,
39
+ "train_loss": 0.16732191265056637,
40
+ "val_loss": 0.2762441613525152,
41
+ "val_iou": 0.8225807750225067,
42
+ "time_sec": 286.4193227291107
43
+ },
44
+ {
45
+ "epoch": 7,
46
+ "train_loss": 0.15182167718914674,
47
+ "val_loss": 0.27510987378656865,
48
+ "val_iou": 0.8245277297496796,
49
+ "time_sec": 294.7808041572571
50
+ },
51
+ {
52
+ "epoch": 8,
53
+ "train_loss": 0.1432231002383762,
54
+ "val_loss": 0.2713714835047722,
55
+ "val_iou": 0.8262266063690186,
56
+ "time_sec": 282.5884385108948
57
+ }
58
+ ]