Upload crossed out text classifier
Browse files
README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- pytorch
|
| 6 |
+
- computer-vision
|
| 7 |
+
- ocr
|
| 8 |
+
- crossed-out-text
|
| 9 |
+
library_name: pytorch
|
| 10 |
+
pipeline_tag: image-classification
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# crossed-out-text-classifier
|
| 14 |
+
|
| 15 |
+
## Model Description
|
| 16 |
+
|
| 17 |
+
This is a ResNet18-based binary classifier trained to detect crossed out text in OCR images. The model classifies images into two categories:
|
| 18 |
+
- `no`: Text is not crossed out
|
| 19 |
+
- `yes`: Text is crossed out
|
| 20 |
+
|
| 21 |
+
## Model Details
|
| 22 |
+
|
| 23 |
+
- **Architecture**: ResNet18 with modified classification head
|
| 24 |
+
- **Parameters**: 11,187,158
|
| 25 |
+
- **Input Size**: 224x224 RGB images
|
| 26 |
+
- **Classes**: ['no', 'yes']
|
| 27 |
+
- **Validation Accuracy**: 0.9688
|
| 28 |
+
- **Training Framework**: PyTorch
|
| 29 |
+
|
| 30 |
+
## Usage
|
| 31 |
+
|
| 32 |
+
### Using the model directly
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
import torch
|
| 36 |
+
from PIL import Image
|
| 37 |
+
import torchvision.transforms as transforms
|
| 38 |
+
|
| 39 |
+
# Load model
|
| 40 |
+
model = torch.load('pytorch_model.bin', map_location='cpu')
|
| 41 |
+
model.eval()
|
| 42 |
+
|
| 43 |
+
# Prepare image
|
| 44 |
+
transform = transforms.Compose([
|
| 45 |
+
transforms.Resize((224, 224)),
|
| 46 |
+
transforms.ToTensor(),
|
| 47 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 48 |
+
])
|
| 49 |
+
|
| 50 |
+
image = Image.open('your_image.png').convert('RGB')
|
| 51 |
+
input_tensor = transform(image).unsqueeze(0)
|
| 52 |
+
|
| 53 |
+
# Make prediction
|
| 54 |
+
with torch.no_grad():
|
| 55 |
+
outputs = model(input_tensor)
|
| 56 |
+
probabilities = torch.nn.functional.softmax(outputs, dim=1)
|
| 57 |
+
predicted_class = torch.argmax(probabilities, dim=1).item()
|
| 58 |
+
confidence = torch.max(probabilities, dim=1)[0].item()
|
| 59 |
+
|
| 60 |
+
class_names = ['no', 'yes']
|
| 61 |
+
print(f"Prediction: {class_names[predicted_class]} (confidence: {confidence:.4f})")
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Using the inference module
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
from src.inference import CrossedOutPredictor
|
| 68 |
+
|
| 69 |
+
# Initialize predictor
|
| 70 |
+
predictor = CrossedOutPredictor()
|
| 71 |
+
predictor.load_model('pytorch_model.bin')
|
| 72 |
+
|
| 73 |
+
# Make prediction
|
| 74 |
+
prediction, confidence = predictor.predict_image('your_image.png')
|
| 75 |
+
print(f"Prediction: {prediction} (confidence: {confidence:.4f})")
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Training Data
|
| 79 |
+
|
| 80 |
+
The model was trained on a dataset of OCR images with crossed out and non-crossed out text. The training used:
|
| 81 |
+
- Data augmentation including rotation, scaling, shearing, and color jittering
|
| 82 |
+
- Transfer learning from ImageNet pretrained ResNet18
|
| 83 |
+
- Two-phase training: frozen backbone followed by full fine-tuning
|
| 84 |
+
|
| 85 |
+
## Limitations
|
| 86 |
+
|
| 87 |
+
- The model is specifically designed for OCR images and may not generalize well to other image types
|
| 88 |
+
- Performance may vary with different text fonts, sizes, or crossing-out patterns
|
| 89 |
+
- Trained on specific image resolution (224x224) and normalization
|
| 90 |
+
|
| 91 |
+
## Intended Use
|
| 92 |
+
|
| 93 |
+
This model is intended for:
|
| 94 |
+
- OCR post-processing pipelines
|
| 95 |
+
- Document analysis systems
|
| 96 |
+
- Text validation workflows
|
| 97 |
+
|
| 98 |
+
## License
|
| 99 |
+
|
| 100 |
+
This model is released under the Apache 2.0 license.
|
| 101 |
+
|
| 102 |
+
## Citation
|
| 103 |
+
|
| 104 |
+
If you use this model, please cite:
|
| 105 |
+
|
| 106 |
+
```bibtex
|
| 107 |
+
@misc{Sleeeepy_crossed_out_text_classifier,
|
| 108 |
+
title={Crossed Out Text Classifier},
|
| 109 |
+
author={Your Name},
|
| 110 |
+
year={2025},
|
| 111 |
+
howpublished={\url{https://huggingface.co/Sleeeepy/crossed-out-text-classifier}}
|
| 112 |
+
}
|
| 113 |
+
```
|