docling-project/DocLayNet-v1.1
Viewer โข Updated โข 63.5k โข 3.12k โข 28
Run jzju/dit-doclaynet on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Use HF Jobs to fine-tune https://huggingface.co/jzju/dit-doclaynet. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Use HF Jobs to run batch inference with https://huggingface.co/jzju/dit-doclaynet on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
How to use jzju/dit-doclaynet with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-segmentation", model="jzju/dit-doclaynet") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoImageProcessor, BeitForSemanticSegmentation
processor = AutoImageProcessor.from_pretrained("jzju/dit-doclaynet")
model = BeitForSemanticSegmentation.from_pretrained("jzju/dit-doclaynet", device_map="auto")# pip install -U transformers accelerate
# Load model directly
from transformers import AutoImageProcessor, BeitForSemanticSegmentation
processor = AutoImageProcessor.from_pretrained("jzju/dit-doclaynet")
model = BeitForSemanticSegmentation.from_pretrained("jzju/dit-doclaynet", device_map="auto")Trained for 4 epochs.
Usage:
image_processor = AutoImageProcessor.from_pretrained("microsoft/dit-large")
model = BeitForSemanticSegmentation.from_pretrained("jzju/dit-doclaynet")
image = Image.open('img.png').convert('RGB')
inputs = image_processor(images=image, return_tensors="pt")
outputs = model(**inputs)
# logits are of shape (batch_size, num_labels, height, width)
logits = outputs.logits
out = logits[0].detach()
out.size()
for i in range(11):
plt.imshow(out[i])
plt.show()
Labels:
1: Caption
2: Footnote
3: Formula
4: List-item
5: Page-footer
6: Page-header
7: Picture
8: Section-header
9: Table
10: Text
11: Title
Data label convert:
model = BeitForSemanticSegmentation.from_pretrained("microsoft/dit-base", num_labels=11)
ds = load_dataset("ds4sd/DocLayNet-v1.1")
mask = np.zeros([11, 1025, 1025])
for b, c in zip(d["bboxes"], d["category_id"]):
b = [np.clip(int(bb), 0, 1025) for bb in b]
mask[c - 1][b[1]:b[1]+b[3], b[0]:b[0]+b[2]] = 1
mask = [cv2.resize(a, dsize=(56, 56), interpolation=cv2.INTER_AREA) for a in mask]
d["label"] = np.stack(mask)
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="jzju/dit-doclaynet")