使用TableGeneration生成表格数据集

1.TableGeneration介绍

TableGeneration是一个可以生成多种格式表格图片的工具,主要用于批量生成给AI训练的表格识别数据,比自己去一个一个截图来的方便。

本文记录的是在win10 64位环境使用TableGeneration的操作细节。

2.TableGeneration使用

2.1配置环境

首先,下载项目到本地,下载地址有两个:

国内镜像:https://gitcode.com/gh_mirrors/ta/TableGeneration/overview
github地址:https://github.com/WenmuZhou/TableGeneration

导入项目到pycharm,在控制台Terminal执行下面的命令:

pip3 install -r requirements.txt

如果有错误提示

Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow
it anyway with '--trusted-host mirrors.aliyun.com'.
ERROR: Could not find a version that satisfies the requirement selenium==3.8.1
ERROR: No matching distribution found for selenium==3.8.1
WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow
it anyway with '--trusted-host mirrors.aliyun.com'.

在上面的命令后面加上--trusted-host mirrors.aliyun.com即可,完整命令如下:

pip3 install -r requirements.txt --trusted-host mirrors.aliyun.com

2.2下载Chrome驱动

找到自己谷歌浏览器的版本,有两种办法:
一是在谷歌浏览器地址栏输入chrome://version/128.0.6613.138这就是版本信息
谷歌浏览器版本
二是点谷歌浏览器右上角的三个竖点,在弹出的框里点击帮助,会出现另外一个小框,里面选择关于 Google Chrome,会切换到关于Chrome的界面,上面也有版本信息。

找到谷歌版本号后,需要下载对应版本的驱动文件,可以从下面的地址获取:

113及以上版本: https://registry.npmmirror.com/binary.html?path=chrome-for-testing/
113及以前的版本: https://registry.npmmirror.com/binary.html?path=chromedriver/
113及以前的版本地址2: https://chromedriver.storage.googleapis.com/index.html

选择最相近的一个版本
128.0.6613.是大版本号,后面的小版本号不是每一个都有,选择最相近的即可。

下载的文件解压后,里面有三个文件,只用看chromedriver.exe即可。
解压后文件

2.3将驱动放入指定目录

找到谷歌浏览器的安装目录,一是通过进程查找,点开谷歌浏览器进程,鼠标点击右键,弹框里选择属性,里面就有谷歌浏览器的位置信息,二是在桌面找到谷歌浏览器的图标,鼠标点击右键,弹框里选择属性,里面就有谷歌浏览器的位置信息。
放入谷歌浏览器驱动
找到你的python安装路径,找到Scripts文件夹,将驱动放入此文件夹内即可。
放入谷歌浏览器驱动

2.4 验证环境

打开pycharm,在控制台Terminal执行下面的命令:

python generate_data.py --output="output/simple_table" --num=1

控制台输出:

Namespace(brower='chrome', brower_height=2440, brower_width=1920, cell_box_type='cell', cell_max_height=0, cell_max_width=0, ch_dict_path='dict/ch_news.txt', color_prob=0, en_dict_path='dict/en_corpus.txt', max_col=10, max_row=15, max_
span_col_count=3, max_span_row_count=3, max_span_value=10, max_txt_len=10, min_col=3, min_row=3, min_txt_len=2, num=1, output='output/simple_table')

DevTools listening on ws://127.0.0.1:51177/devtools/browser/1f7248ab-4d61-4bf5-920d-eaa808323b91
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:01<00:00,  1.40s/it]

生成的文件信息
生成的图片和html
图片

3参数说明

output:表格图片文件输出目录
num:生成表格图片的数量

# 简单表格
python generate_data.py --output="output/simple_table" --num=1
# 单元格坐标为单元格内文字坐标的表格
python generate_data.py --output="output/simple_table" --num=1 --cell_box_type='text'
# 彩色单元格表格
python generate_data.py --output="output/color_simple_table" --num=1 --color_prob=0.3
# 清单类表格
python generate_data.py --output="output/qd_table" --num=1 --min_row=10 --max_row=80 --min_col=4 --max_col=8 --min_txt_len=2 --max_txt_len=10 --max_span_row_count=3 --max_span_col_count=3 --max_span_value=20 --color_prob=0 --brower_width=1920 --brower_height=5000
# 大单元格表格
python generate_data.py --output="output/big_cell_table" --num=1 --min_row=6 --max_row=10 --min_col=4 --max_col=8 --min_txt_len=2 --max_txt_len=10 --max_span_row_count=3 --max_span_col_count=3 --max_span_value=10 --color_prob=0 --cell_max_width=100 --cell_max_height=100 --brower_width=1920 --brower_height=1920
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值