nielsr HF staff commited on
Commit
b47dc23
1 Parent(s): b39aaad

Add link to model doc

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -9,6 +9,8 @@ import cv2
9
 
10
  from unilm.dit.object_detection.ditod import add_vit_config
11
 
 
 
12
  from detectron2.config import CfgNode as CN
13
  from detectron2.config import get_cfg
14
  from detectron2.utils.visualizer import ColorMode, Visualizer
@@ -27,8 +29,7 @@ cfg.merge_from_file("cascade_dit_base.yml")
27
  cfg.MODEL.WEIGHTS = "https://layoutlm.blob.core.windows.net/dit/dit-fts/publaynet_dit-b_cascade.pth"
28
 
29
  # Step 3: set device
30
- # TODO also support GPU
31
- cfg.MODEL.DEVICE='cpu'
32
 
33
  # Step 4: define model
34
  predictor = DefaultPredictor(cfg)
@@ -53,7 +54,7 @@ def analyze_image(img):
53
 
54
  title = "Interactive demo: Document Layout Analysis with DiT"
55
  description = "Demo for Microsoft's DiT, the Document Image Transformer for state-of-the-art document understanding tasks. This particular model is fine-tuned on PubLayNet, a large dataset for document layout analysis (read more at the links below). To use it, simply upload an image or use the example image below and click 'Submit'. Results will show up in a few seconds. If you want to make the output bigger, right-click on it and select 'Open image in new tab'."
56
- article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2203.02378' target='_blank'>DiT: Self-supervised Pre-training for Document Image Transformer</a> | <a href='https://github.com/microsoft/unilm/dit' target='_blank'>Github Repo</a></p>"
57
  examples =[['publaynet_example.jpeg']]
58
  css = ".output-image, .input-image, .image-preview {height: 600px !important}"
59
 
 
9
 
10
  from unilm.dit.object_detection.ditod import add_vit_config
11
 
12
+ import torch
13
+
14
  from detectron2.config import CfgNode as CN
15
  from detectron2.config import get_cfg
16
  from detectron2.utils.visualizer import ColorMode, Visualizer
 
29
  cfg.MODEL.WEIGHTS = "https://layoutlm.blob.core.windows.net/dit/dit-fts/publaynet_dit-b_cascade.pth"
30
 
31
  # Step 3: set device
32
+ cfg.MODEL.DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
 
33
 
34
  # Step 4: define model
35
  predictor = DefaultPredictor(cfg)
 
54
 
55
  title = "Interactive demo: Document Layout Analysis with DiT"
56
  description = "Demo for Microsoft's DiT, the Document Image Transformer for state-of-the-art document understanding tasks. This particular model is fine-tuned on PubLayNet, a large dataset for document layout analysis (read more at the links below). To use it, simply upload an image or use the example image below and click 'Submit'. Results will show up in a few seconds. If you want to make the output bigger, right-click on it and select 'Open image in new tab'."
57
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2203.02378' target='_blank'>DiT: Self-supervised Pre-training for Document Image Transformer</a> | <a href='https://github.com/microsoft/unilm/tree/master/dit' target='_blank'>Github Repo</a></p> | <a href='https://huggingface.co/docs/transformers/master/en/model_doc/dit' target='_blank'>HuggingFace model doc</a></p>"
58
  examples =[['publaynet_example.jpeg']]
59
  css = ".output-image, .input-image, .image-preview {height: 600px !important}"
60