Meta的OCR神器nougat强出了天际,赶紧试用一番!

本文介绍了Meta出品的NougatOCR工具,它能识别PDF文件中的文本,支持分页处理和简单安装。文章详细讲解了如何使用Python库进行PDF拆分和安装Nougat,以及基本的运行方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

摘要

https://arxiv.org/pdf/2308.13418.pdf
https://github.com/facebookresearch/nougat

nougat:你们能识别的,我可以识别,你们不能识别的,我也可以识别,Meta出品,大厂背景!这就是nougat!!!

切页

试用了一番nougat,很强!很牛!但是也很耗显存,为了省显存,只能先做点处理,首先将PDF文档转成一页一页的,代码如下:

"""
	用途:将一个 PDF 文件按页拆分为多个 PDF 文件

    注意事项:若报错 ModuleNotFoundError: No module named 'PyPDF2'
             则需要先安装该模块。使用命令 “pip install PyPDF2” 安装即可
"""


import PyPDF2  # 需要先安装:pip/pip3 install PyPDF2
import os

# root = r'C:\Users\liujieru\Documents\pdf'  # 源文件所在的绝对路径
# file_path = os.path.join(root, '组合.pdf')
file_path='2308.13418.pdf'
pdf_file = open(file_path, 'rb')  # 获取原 PDF 文件
pdf_reader = PyPDF2.PdfReader(pdf_file)  # 创建 PDF 对象
source_name = pdf_file.name  # 获取源文件名称,包含绝对路径

pdf_writer = PyPDF2.PdfWriter()  # 创建一个空白 PDF 对象

for page_num in range(len(pdf_reader.pages)):  # 将每页内容分别写入一个新文件
    page_obj =pdf_reader.pages[page_num]# pdf_reader.getPage(page_num)
    pdf_writer.add_page(page_obj)  # 向空白 PDF 对象中添加要复制的 PDF页面

    new_name = source_name[:-4] + str(page_num) + ".pdf"
    pdf_new_file = open(new_name, 'wb')  # 创建一个新文件
    pdf_writer.write(pdf_new_file)  # 将添加了内容的空白 PDF 对象,写入到新建文件中
    pdf_new_file.close()

    pdf_writer.__init__()  # 将 PDF 对象初始化

pdf_file.close()

PDF就用论文了!

转成之后,我们就开始安装nougat,

安装

From pip:

pip install nougat-ocr

From repository:

pip install git+https://github.com/facebookresearch/nougat

There are extra dependencies if you want to call the model from an API or generate a dataset.
Install via

pip install "nougat-ocr[api]" or pip install "nougat-ocr[dataset]"

好吧!主打的就是简单!!!

运行

这个就更简单了!

nougat path/to/file.pdf

我将PDF已经切成一页一页的,然后,我们测试第一页!

nougat 2308.134180.pdf

在这里插入图片描述

如果你想保存成文件,可以增加输出的路径!

nougat 2308.134181.pdf --out out

在这里插入图片描述
打开看看效果如何?

在这里插入图片描述
Mete最近有疯狂,疯狂的开源!
如果大家不能下载权重文件,可以用下面的链接!
https://download.csdn.net/download/hhhhhhhhhhwwwwwwwwww/88301373

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI浩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值