nielsr HF staff commited on
Commit
ccf3e12
1 Parent(s): 3f9d5ab

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -0
README.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+
3
+ inference: false
4
+ ---
5
+
6
+ # Document Image Transformer (base-sized model)
7
+
8
+ Document Image Transformer (DiT) model pre-trained on IIT-CDIP (Lewis et al., 2006), a dataset that includes 42 million document images and fine-tuned on [RVL-CDIP](https://www.cs.cmu.edu/~aharley/rvl-cdip/), a dataset consisting of 400,000 grayscale images in 16 classes, with 25,000 images per class. It was introduced in the paper [DiT: Self-supervised Pre-training for Document Image Transformer](https://arxiv.org/abs/2203.02378) by Li et al. and first released in [this repository](https://github.com/microsoft/unilm/tree/master/dit). Note that DiT is identical to the architecture of [BEiT](https://huggingface.co/docs/transformers/model_doc/beit).
9
+
10
+ Disclaimer: The team releasing DiT did not write a model card for this model so this model card has been written by the Hugging Face team.
11
+
12
+ ## Model description
13
+
14
+ The Document Image Transformer (DiT) is a transformer encoder model (BERT-like) pre-trained on a large collection of images in a self-supervised fashion. The pre-training objective for the model is to predict visual tokens from the encoder of a discrete VAE (dVAE), based on masked patches.
15
+
16
+ Images are presented to the model as a sequence of fixed-size patches (resolution 16x16), which are linearly embedded. One also adds absolute position embeddings before feeding the sequence to the layers of the Transformer encoder.
17
+
18
+ By pre-training the model, it learns an inner representation of images that can then be used to extract features useful for downstream tasks: if you have a dataset of labeled document images for instance, you can train a standard classifier by placing a linear layer on top of the pre-trained encoder.
19
+
20
+ ## Intended uses & limitations
21
+
22
+ You can use the raw model for encoding document images into a vector space, but it's mostly meant to be fine-tuned on tasks like document image classification, table detection or document layout analysis. See the [model hub](https://huggingface.co/models?search=microsoft/dit) to look for fine-tuned versions on a task that interests you.
23
+
24
+ ### How to use
25
+
26
+ Here is how to use this model in PyTorch:
27
+
28
+ ```python
29
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
30
+ import torch
31
+ from PIL import Image
32
+
33
+ image = Image.open('path_to_your_document_image').convert('RGB')
34
+
35
+ feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/dit-base-finetuned-rvlcdip")
36
+ model = AutoModelForImageClassification.from_pretrained("microsoft/dit-base-finetuned-rvlcdip")
37
+
38
+ inputs = feature_extractor(images=image, return_tensors="pt")
39
+ outputs = model(**inputs)
40
+ logits = outputs.logits
41
+
42
+ # model predicts one of the 16 RVL-CDIP classes
43
+ predicted_class_idx = logits.argmax(-1).item()
44
+ print("Predicted class:", model.config.id2label[predicted_class_idx])
45
+ ```
46
+
47
+ ### BibTeX entry and citation info
48
+
49
+ ```bibtex
50
+ @article{Lewis2006BuildingAT,
51
+ title={Building a test collection for complex document information processing},
52
+ author={David D. Lewis and Gady Agam and Shlomo Engelson Argamon and Ophir Frieder and David A. Grossman and Jefferson Heard},
53
+ journal={Proceedings of the 29th annual international ACM SIGIR conference on Research and development in information retrieval},
54
+ year={2006}
55
+ }
56
+ ```