PubLayNet:文档布局分析领域的大规模数据集
PubLayNet:文档布局分析领域的大规模数据集
1. 数据集概述
PubLayNet(Public Layout Network)是由IBM AUR NLP团队开发的大规模文档图像数据集,旨在推动文档理解与布局分析领域的研究。该数据集通过自动标注技术,对科学文献的版面元素(如文本、标题、表格等)提供高精度的边界框和多边形分割注释,是目前文档布局分析领域规模最大、标注最完善的开放数据集之一
2. 核心特性与数据规模
2.1 数据构成
- 数据来源:基于PubMed Central Open Access子集的科研论文(商业用途许可),覆盖生物医学、计算机科学等多学科领域
- 标注类别:5类文档元素(Text/文本、Title/标题、List/列表、Table/表格、Figure/图表)
- 数据量:
数据集类型 图像数量 训练集 333,703张 验证集 11,245张 测试集 11,405张
2.2 技术亮点
- 标注质量:通过PDF与XML格式匹配自动生成注释,并采用质量控制指标(99%面积覆盖率筛选)确保标注精度
- 多模态支持:同时提供边界框(Bounding Box)和多边形分割(Polygon Segmentation)两种标注形式
3. 数据构建方法
PubLayNet的构建采用创新的自动化流程:
- 格式匹配:将PDF文档的视觉元素与XML结构化内容对齐,利用PDFMiner解析阅读顺序和文本块位置
- 模糊匹配算法:通过阈值控制的字符串相似度计算,解决PDF与XML文本的微小差异问题
- 质量过滤:排除注释覆盖率低于99%的非标题页,确保数据可靠性
4. 小批量数据可视化脚本
# importing prerequisites
import sys
import requests
import tarfile
import json
import numpy as np
from os import path
from PIL import Image
from PIL import ImageFont, ImageDraw
from glob import glob
from matplotlib import pyplot as plt
# %matplotlib inline
fname = 'examples.tar.gz'
url = 'https://dax-cdn.cdn.appdomain.cloud/dax-publaynet/1.0.0/' + fname
r = requests.get(url)
open(fname , 'wb').write(r.content)# Extracting the dataset
tar = tarfile.open(fname)
tar.extractall()
tar.close()# Verifying the file was extracted properly
data_path = "examples/"
path.exists(data_path)# Define color code
colors = {'title': (255, 0, 0),'text': (0, 255, 0),'figure': (0, 0, 255),'table': (255, 255, 0),'list': (0, 255, 255)}# Function to viz the annotation
def markup(image, annotations):''' Draws the segmentation, bounding box, and label of each annotation'''draw = ImageDraw.Draw(image, 'RGBA')for annotation in annotations:# Draw segmentationdraw.polygon(annotation['segmentation'][0],fill=colors[samples['categories'][annotation['category_id'] - 1]['name']] + (64,))# Draw bboxdraw.rectangle((annotation['bbox'][0],annotation['bbox'][1],annotation['bbox'][0] + annotation['bbox'][2],annotation['bbox'][1] + annotation['bbox'][3]),outline=colors[samples['categories'][annotation['category_id'] - 1]['name']] + (255,),width=2)# Draw labelw, h = draw.textsize(text=samples['categories'][annotation['category_id'] - 1]['name'],font=font)if annotation['bbox'][3] < h:draw.rectangle((annotation['bbox'][0] + annotation['bbox'][2],annotation['bbox'][1],annotation['bbox'][0] + annotation['bbox'][2] + w,annotation['bbox'][1] + h),fill=(64, 64, 64, 255))draw.text((annotation['bbox'][0] + annotation['bbox'][2],annotation['bbox'][1]),text=samples['categories'][annotation['category_id'] - 1]['name'],fill=(255, 255, 255, 255),font=font)else:draw.rectangle((annotation['bbox'][0],annotation['bbox'][1],annotation['bbox'][0] + w,annotation['bbox'][1] + h),fill=(64, 64, 64, 255))draw.text((annotation['bbox'][0],annotation['bbox'][1]),text=samples['categories'][annotation['category_id'] - 1]['name'],fill=(255, 255, 255, 255),font=font)return np.array(image)# Parse the JSON file and read all the images and labels
with open('examples/samples.json', 'r') as fp:samples = json.load(fp)
# Index images
images = {}
for image in samples['images']:images[image['id']] = {'file_name': "examples/" + image['file_name'], 'annotations': []}
for ann in samples['annotations']:images[ann['image_id']]['annotations'].append(ann)
# Visualize annotations
font = ImageFont.truetype("examples/DejaVuSans.ttf", 15)
fig=plt.figure(figsize=(16, 100))
for i, (_, image) in enumerate(images.items()):with Image.open(image['file_name']) as img:ax = plt.subplot(int(len(images) / 2), 2, i + 1)ax.imshow(markup(img, image['annotations']))ax.axis('off')
plt.subplots_adjust(hspace=0, wspace=0)
plt.savefig('examples/annotations.png')
5. 获取与使用
- 下载地址:IBM开发者平台
- 许可协议:遵循CDLA-Permissive开源协议,允许商业用途
- 快速体验:提供预训练模型和演示脚本,支持快速部署
参考文献
- 推荐开源项目:PubLayNet——文档图像布局标注的利器
- PubLayNet数据集文档
- PubLayNet官方介绍
- PubLayNet技术应用分析
- 基于PubLayNet的Transformer模型研究
- PubLayNet数据规模说明
- 多模态方法在PubLayNet上的应用
- CSDN技术博客
- PaddleDetection模型库
- 数据生成方法详解