Text recognition model for
CrispEmbed .
Recognizes printed text from cropped text-line images. Pair with a text detector
like
cstr/dbnet-ic15-GGUF for
end-to-end OCR.
Note: trocr-small-printed uppercases output (training data bias). For
mixed-case, use a trocr-base model.
1 crispembed --det dbnet-ic15-q4_k.gguf \
2 -m trocr-small-printed-q8_0.gguf \
3 --ocr document.png
[ 0] (49,53)-(143,86) conf=0.91 "HELLO"
[ 1] (153,52)-(270,86) conf=0.91 "WORLD!"
[ 2] (50,122)-(124,157) conf=0.91 "THIS"
...
1 # include "crispembed.h"
2
3 void * ctx = crispembed_ocr_init ( "dbnet-ic15-q4_k.gguf" ,
4 "trocr-small-printed-q8_0.gguf" , 4 ) ;
5 int n ;
6 const crispembed_ocr_result * r = crispembed_ocr ( ctx , "document.png" , & n ) ;
7 for ( int i = 0 ; i < n ; i ++ )
8 printf ( "%s " , r [ i ] . text ) ;
9 crispembed_ocr_free ( ctx ) ;
Input: text crop (resized to 384x384, grayscale)
|
+-> DeiT-small encoder (12 layers)
| 16x16 patch embedding -> 576+2 tokens (CLS + distillation)
| 12x Pre-LN MHA (6 heads, 384d) + FFN (GELU, 1536d)
|
+-> TrOCR decoder (6 layers, autoregressive)
Token + position embedding (64044 BPE vocab, 514 max positions)
6x Self-attn (causal) + Cross-attn + FFN
-> greedy argmax -> SentencePiece BPE detokenize
XLM-R SentencePiece tokenizer with fairseq vocab offset. Word boundaries
marked by ▁ (U+2581), converted to spaces at decode time.
1 pip install gguf numpy transformers sentencepiece safetensors
2
3 # Download model
4 python -c "from huggingface_hub import snapshot_download; \
5 snapshot_download('microsoft/trocr-small-printed', local_dir='trocr-small-printed')"
6
7 # Convert (embeds XLM-R tokenizer via AutoTokenizer)
8 python models/convert-trocr-to-gguf.py \
9 --model-dir trocr-small-printed/ \
10 --output trocr-small-printed-f32.gguf
11
12 # Quantize (Q8_0 recommended; Q4_K degrades this model)
13 crispembed-quantize trocr-small-printed-f32.gguf trocr-small-printed-q8_0.gguf q8_0