Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,75 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
---
|
4 |
+
|
5 |
+
![alt text](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSksxbjFqxppkfVHAN30x6JjNc_3JGeGILZPA&s "Title")
|
6 |
+
|
7 |
+
|
8 |
+
# Fine Tuning Script For Layout Model Of Surya OCR.
|
9 |
+
|
10 |
+
This repository contains [layout-fine-tune.ipynb](https://huggingface.co/ketanmore/surya-layout-fine-tune-script/blob/main/layout-fine-tune.ipynb) file, Please use this file to fine tune [Surya Layout Model](https://huggingface.co/vikp/surya_layout2). This model uses modified architecture of Segformer.
|
11 |
+
|
12 |
+
## Setup Instructions
|
13 |
+
|
14 |
+
### Clone the Surya OCR GitHub Repository
|
15 |
+
|
16 |
+
```bash
|
17 |
+
git clone https://github.com/vikp/surya.git
|
18 |
+
cd surya
|
19 |
+
```
|
20 |
+
|
21 |
+
### Switch to v0.4.14
|
22 |
+
|
23 |
+
```bash
|
24 |
+
git checkout f7c6c04
|
25 |
+
```
|
26 |
+
|
27 |
+
### Install Dependencies
|
28 |
+
|
29 |
+
You can install the required dependencies using the following command:
|
30 |
+
|
31 |
+
```bash
|
32 |
+
pip install -r requirements.txt
|
33 |
+
```
|
34 |
+
|
35 |
+
# Image Pre-processing
|
36 |
+
|
37 |
+
For image pre-processing we can directly import a function and image processor from [surya ocr github repository](https://github.com/VikParuchuri/surya/tree/v0.4.14).
|
38 |
+
|
39 |
+
```python
|
40 |
+
from surya.input.processing import prepare_image_detection
|
41 |
+
```
|
42 |
+
|
43 |
+
```python
|
44 |
+
from surya.model.detection.segformer import load_processor
|
45 |
+
```
|
46 |
+
|
47 |
+
```python
|
48 |
+
from PIL import Image
|
49 |
+
image = Image.open("path/to/image)
|
50 |
+
images = [prepare_image_detection(img=image, processor=load_processor())]
|
51 |
+
```
|
52 |
+
|
53 |
+
```python
|
54 |
+
import torch
|
55 |
+
images = torch.stack(images, dim=0).to(model.dtype).to(model.device)
|
56 |
+
```
|
57 |
+
|
58 |
+
# Loading Model
|
59 |
+
|
60 |
+
```python
|
61 |
+
from surya.model.detection.segformer import load_model
|
62 |
+
```
|
63 |
+
|
64 |
+
```python
|
65 |
+
model = load_model("vikp/surya_layout2")
|
66 |
+
```
|
67 |
+
|
68 |
+
```python
|
69 |
+
output = model(pixel_values=images)
|
70 |
+
```
|
71 |
+
|
72 |
+
|
73 |
+
### Note : Loss function
|
74 |
+
|
75 |
+
[Surya-layout-Model](https://huggingface.co/vikp/surya_layout2) does not have pre-defined loss function, We have to define it according to our dataset and the Requirements.
|