Update README.md
Browse files
README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
```python
|
|
|
|
|
|
|
| 2 |
from transformers import VisionEncoderDecoderModel, AutoTokenizer
|
|
|
|
| 3 |
tokenizer = AutoTokenizer.from_pretrained('tirthadagr8/CustomOCR')
|
| 4 |
model=VisionEncoderDecoderModel.from_pretrained('tirthadagr8/CustomOCR')
|
| 5 |
import torch
|
|
@@ -9,12 +12,12 @@ simple_transforms=T.Compose([
|
|
| 9 |
T.ToTensor(),
|
| 10 |
T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 11 |
])
|
| 12 |
-
|
| 13 |
path="image.jpg"
|
| 14 |
img=simple_transforms(Image.open(path))
|
| 15 |
model.eval()
|
| 16 |
with torch.no_grad():
|
| 17 |
print(tokenizer.batch_decode(model.cuda().generate(img.unsqueeze(0).cuda()),skip_special_tokens=True))
|
| 18 |
-
|
| 19 |
plt.imshow(Image.open(path).resize((224,224)))
|
| 20 |
```
|
|
|
|
| 1 |
```python
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
from transformers import VisionEncoderDecoderModel, AutoTokenizer
|
| 5 |
+
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained('tirthadagr8/CustomOCR')
|
| 7 |
model=VisionEncoderDecoderModel.from_pretrained('tirthadagr8/CustomOCR')
|
| 8 |
import torch
|
|
|
|
| 12 |
T.ToTensor(),
|
| 13 |
T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 14 |
])
|
| 15 |
+
|
| 16 |
path="image.jpg"
|
| 17 |
img=simple_transforms(Image.open(path))
|
| 18 |
model.eval()
|
| 19 |
with torch.no_grad():
|
| 20 |
print(tokenizer.batch_decode(model.cuda().generate(img.unsqueeze(0).cuda()),skip_special_tokens=True))
|
| 21 |
+
|
| 22 |
plt.imshow(Image.open(path).resize((224,224)))
|
| 23 |
```
|