Sharing models#
docTR is integrated with the Hugging Face Hub: load models shared by the community in one line, and publish your own.
Load a model from the Hub#
from_hub() downloads a model and rebuilds it with its configuration (architecture, vocabulary,
classes…). Plug it into any predictor:
from doctr.io import DocumentFile
from doctr.models import from_hub, ocr_predictor
det_model = from_hub("Felix92/doctr-torch-db-mobilenet-v3-large")
reco_model = from_hub("Felix92/doctr-torch-parseq-multilingual-v1")
predictor = ocr_predictor(det_arch=det_model, reco_arch=reco_model)
result = predictor(DocumentFile.from_images("path/to/page.jpg"))
Publish a model#
You need a Hugging Face account and Git LFS installed.
from doctr.models import login_to_hub, push_to_hf_hub, recognition
login_to_hub() # paste an access token with write permissions
model = recognition.crnn_mobilenet_v3_large(pretrained=True)
push_to_hf_hub(
model,
model_name="doctr-crnn-mobilenet-v3-large-french-v1",
task="recognition", # classification, detection, recognition, layout or table_structure
arch="crnn_mobilenet_v3_large",
)
Existing repositories are never overwritten. The reference training scripts can also publish the model at the end of the training:
python references/recognition/train.py crnn_mobilenet_v3_large --name doctr-crnn-mobilenet-v3-large --push-to-hub
Naming conventions#
Task |
Suggested name |
|---|---|
Classification |
|
Detection |
|
Recognition |
|
Layout |
|
Table structure |
|
Community models#
Models trained and shared by the community. Open a pull request to add yours!
Task |
Architecture |
Repository |
Language |
|---|---|---|---|
Detection |
|
Arabic |
|
Recognition |
|
Multilingual |
|
Recognition |
|
Arabic |
|
Recognition |
|
French + German + § |
Dummy models, handy for tests: Felix92/doctr-dummy-torch-resnet18 (classification),
Felix92/doctr-dummy-torch-lw-detr-s (layout) and
Felix92/doctr-dummy-torch-tablecenternet (table structure).