当前位置: 首页 > news >正文

南昌网站关键词优化爱论坛

南昌网站关键词优化,爱论坛,关于做ppt的网站,西安疫情最新调整虽然最近我花了很多时间在大型语言模型 (LLM) 上进行实验,但我对计算机视觉的热情始终未减。因此,当我有机会将两者融合在一起时,我迫不及待地想要立即开始。在 Goodreads 上扫描书籍封面并将其标记为已读一直感觉有点神奇,我很兴…

虽然最近我花了很多时间在大型语言模型 (LLM) 上进行实验,但我对计算机视觉的热情始终未减。因此,当我有机会将两者融合在一起时,我迫不及待地想要立即开始。在 Goodreads 上扫描书籍封面并将其标记为已读一直感觉有点神奇,我很兴奋自己尝试一下。

将自定义训练的 YOLOv10 模型与 OCR 技术相结合可显著提高准确率,但真正的转变发生在集成 LLM(如 Llama 3.1)时——它将杂乱的 OCR 输出转换为可用于实际应用的精致文本。

NSDT工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器 - REVIT导出3D模型插件 - 3D模型语义搜索引擎 - AI模型在线查看 - Three.js虚拟轴心开发包 - 3D模型在线减面 - STL模型在线切割 

1、为什么需要 YOLO 、Ollama 和OCR?

传统的 OCR(光学字符识别)方法非常适合从简单图像中提取文本,但当文本与其他视觉元素交织在一起时,通常会遇到困难。通过首先使用自定义 YOLO 模型检测文本区域等对象,我们可以隔离这些区域以进行 OCR,从而显著减少噪音并提高准确率。

让我们通过在没有 YOLO 的图像上运行基本的 OCR 示例来证明这一点,以强调单独使用 OCR 的挑战:

import easyocr
import cv2
# Initialize EasyOCR
reader = easyocr.Reader(['en'])
# Load the image
image = cv2.imread('book.jpg')
# Run OCR directly
results = reader.readtext(image)
# Display results
for (bbox, text, prob) in results:print(f"Detected Text: {text} (Probability: {prob})")

输出结果如下:

THE 0 R |G |NAL B E STSELLE R THE SECRET HISTORY DONNA TARTT Haunting, compelling and brilliant The Times 

虽然这种方法适用于较简单的图像,但当存在噪声或复杂的视觉模式时,你会注意到错误会增加。这时 YOLO 模型可以发挥巨大作用。

2、使用自定义数据集训练 Yolov10

使用对象检测增强 OCR 的第一步是在数据集上训练自定义 YOLO 模型。

YOLO(You Only Look Once)是一种功能强大的实时对象检测模型,它将图像划分为网格,使其能够在一次前向传递中识别多个对象。这种方法非常适合检测图像中的文本,尤其是当你想要通过隔离特定区域来改善 OCR 结果时。

我们将使用此处链接的预标注书籍封面数据集,并在其上训练 YOLOv10 模型。YOLOv10 针对较小的物体进行了优化,使其非常适合在视频或扫描文档等具有挑战性的环境中检测文本。

from ultralytics import YOLOmodel = YOLO("yolov10n.pt")
# Train the model
model.train(data="datasets/data.yaml", epochs=50, imgsz=640)

就我而言,在 Google Colab 上训练此模型大约需要 6 个小时,共 50 个 epoch。你可以调整 epoch 数量、数据集大小或超参数等参数来提高模型的性能和准确性。

2、在视频上运行自定义模型以获取边界框

YOLO 模型训练完成后,您可以将其应用于视频以检测文本区域周围的边界框。这些边界框隔离了感兴趣的区域,确保 OCR 过程更加清晰:

import cv2
# Open video file
video_path = 'books.mov'
cap = cv2.VideoCapture(video_path)
# Load YOLO model
model = YOLO('model.pt')
# Function for object detection and drawing bounding boxes
def predict_and_detect(model, frame, conf=0.5):results = model.predict(frame, conf=conf)for result in results:for box in result.boxes:# Draw bounding boxx1, y1, x2, y2 = map(int, box.xyxy[0].tolist())cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)return frame, results
# Process video frames
while cap.isOpened():ret, frame = cap.read()if not ret:break# Run object detectionprocessed_frame, results = predict_and_detect(model, frame)# Show video with bounding boxescv2.imshow('YOLO + OCR Detection', processed_frame)if cv2.waitKey(1) & 0xFF == ord('q'):break
# Release video
cap.release()
cv2.destroyAllWindows()

该代码实时处理视频,在检测到的文本周围绘制边界框,并为下一步 OCR 准备这些区域。

3、在边界框上运行 OCR

现在我们已经使用 YOLO 隔离了文本区域,我们可以在这些特定区域内应用 OCR,与在整个图像上运行 OCR 相比,这大大提高了准确性:

import easyocr
# Initialize EasyOCR
reader = easyocr.Reader(['en'])
# Function to crop frames and perform OCR
def run_ocr_on_boxes(frame, boxes):ocr_results = []for box in boxes:x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())cropped_frame = frame[y1:y2, x1:x2]ocr_result = reader.readtext(cropped_frame)ocr_results.append(ocr_result)return ocr_results
# Perform OCR on detected bounding boxes
for result in results:ocr_results = run_ocr_on_boxes(frame, result.boxes)# Extract and display the text from OCR resultsextracted_text = [detection[1] for ocr in ocr_results for detection in ocr]print(f"Extracted Text: {', '.join(extracted_text)}")

输出结果如下:

'THE, SECRET, HISTORY, DONNA, TARTT'

结果明显改善,因为 OCR 引擎现在只处理明确标识为包含文本的区域,从而降低了因不相关图像元素而产生误解的风险。

4、使用 Ollama 改进文本

使用 easyocr 提取文本后,Ollama 的 Llama 3.1 可以进一步完善通常不完美且混乱的结果。OCR 功能强大,但它仍然可能误解文本或无序返回数据,尤其是书名或作者姓名。

Ollama 的 Llama 3.1 介入清理输出,从原始 OCR 结果中提供结构化、连贯的文本。通过向 Llama 3.1 提供识别和组织文本的具体说明,我们可以将不完美的 OCR 输出转换为格式整齐的书名和作者姓名。

import ollama
# Construct a prompt to clean up the OCR output
prompt = f"""
- Below is a text extracted from an OCR. The text contains mentions of famous books and their corresponding authors.
- Some words may be slightly misspelled or out of order.
- Your task is to identify the book titles and corresponding authors from the text.
- Output the text in the format: '<Name of the book> : <Name of the author>'.
- Do not generate any other text except the book title and the author.
TEXT:
{output_text}
"""
# Use Ollama to clean and structure the OCR output
response = ollama.chat(model="llama3",messages=[{"role": "user", "content": prompt}]
)
# Extract cleaned text
cleaned_text = response['message']['content'].strip()
print(cleaned_text)

输出结果如下:

The Secret History : Donna Tartt

一旦 Llama 3.1 清理了文本,经过润色的输出就可以存储在数据库中或用于各种实际应用,例如:

  • 数字图书馆或书店:自动对书名进行分类,并在作者旁边显示书名。
  • 档案系统:将扫描的书籍封面或文档转换为可搜索的数字记录。
  • 自动元数据生成:根据提取的信息为图像、PDF 或其他数字资产生成元数据。
  • 数据库输入:将清理后的文本直接插入数据库,确保大型系统的数据结构化和一致性。

通过结合对象检测、OCR 和 LLM,你可以解锁强大的管道,以实现更结构化的数据处理,非常适合需要高精度水平的应用程序。

5、结束语

通过将定制训练的 YOLOv10 模型与 EasyOCR 相结合并使用 Ollama 的 Llama 3.1 增强结果,你可以显著改善文本识别工作流程。无论是在检测复杂图像或视频中的文本、清理 OCR 结果还是使输出更易于使用,此管道都可以实现实时、高度准确的文本提取和细化。

完整的源代码和 Jupyter Notebook 可在 GitHub 存储库中找到。


原文链接:YOLO和LLM增强的OCR - BimAnt


文章转载自:
http://hoggerel.xqwq.cn
http://strong.xqwq.cn
http://chitin.xqwq.cn
http://incogitable.xqwq.cn
http://microgamete.xqwq.cn
http://floridity.xqwq.cn
http://metacinnabarite.xqwq.cn
http://nordic.xqwq.cn
http://necessity.xqwq.cn
http://pluriaxial.xqwq.cn
http://monarchism.xqwq.cn
http://zoophysics.xqwq.cn
http://recline.xqwq.cn
http://ketosteroid.xqwq.cn
http://promptbook.xqwq.cn
http://zain.xqwq.cn
http://crustless.xqwq.cn
http://ionomer.xqwq.cn
http://decolorimeter.xqwq.cn
http://laryngectomee.xqwq.cn
http://tetramer.xqwq.cn
http://cytotropism.xqwq.cn
http://hydroxyphenyl.xqwq.cn
http://heckelphone.xqwq.cn
http://consenting.xqwq.cn
http://pentecost.xqwq.cn
http://muckamuck.xqwq.cn
http://detriment.xqwq.cn
http://planetokhod.xqwq.cn
http://sugarcane.xqwq.cn
http://unpatterned.xqwq.cn
http://spiniform.xqwq.cn
http://slimmer.xqwq.cn
http://dirtily.xqwq.cn
http://loader.xqwq.cn
http://epicardial.xqwq.cn
http://erroneous.xqwq.cn
http://diseur.xqwq.cn
http://transmutation.xqwq.cn
http://wallasey.xqwq.cn
http://prolix.xqwq.cn
http://remediable.xqwq.cn
http://seignior.xqwq.cn
http://nard.xqwq.cn
http://drone.xqwq.cn
http://clericalization.xqwq.cn
http://rowel.xqwq.cn
http://us.xqwq.cn
http://norwards.xqwq.cn
http://caudal.xqwq.cn
http://itinerant.xqwq.cn
http://yagi.xqwq.cn
http://manlike.xqwq.cn
http://year.xqwq.cn
http://ultramontane.xqwq.cn
http://grunion.xqwq.cn
http://kennebec.xqwq.cn
http://gamahuche.xqwq.cn
http://sappan.xqwq.cn
http://fib.xqwq.cn
http://nationalize.xqwq.cn
http://scotopic.xqwq.cn
http://nominal.xqwq.cn
http://crossbedded.xqwq.cn
http://spitfire.xqwq.cn
http://luminol.xqwq.cn
http://toupee.xqwq.cn
http://meiosis.xqwq.cn
http://wiretap.xqwq.cn
http://fnma.xqwq.cn
http://pyogenic.xqwq.cn
http://bottle.xqwq.cn
http://sensoria.xqwq.cn
http://energic.xqwq.cn
http://benefactress.xqwq.cn
http://nida.xqwq.cn
http://satyromania.xqwq.cn
http://photomagnetic.xqwq.cn
http://mixt.xqwq.cn
http://snowball.xqwq.cn
http://juichin.xqwq.cn
http://vehiculum.xqwq.cn
http://myotic.xqwq.cn
http://rcvs.xqwq.cn
http://epithelioid.xqwq.cn
http://winterbeaten.xqwq.cn
http://orthographic.xqwq.cn
http://hedda.xqwq.cn
http://bosthoon.xqwq.cn
http://mercapto.xqwq.cn
http://desirability.xqwq.cn
http://ruddiness.xqwq.cn
http://emulator.xqwq.cn
http://altarwise.xqwq.cn
http://arthroscope.xqwq.cn
http://secretive.xqwq.cn
http://lares.xqwq.cn
http://overchoice.xqwq.cn
http://squarish.xqwq.cn
http://moujik.xqwq.cn
http://www.hrbkazy.com/news/66094.html

相关文章:

  • 怎么做网站淘宝转换工具网站关键词公司
  • 糕点网站策划书推广策略及推广方式
  • 建始县城乡建设局网站关键字排名优化公司
  • 大学生毕业设计课题做网站抚州网络推广
  • 开网站赚50万做长沙网站开发制作
  • 网站关键字如何做如何注册一个域名
  • 做bjd娃娃的手工网站广告设计与制作
  • 499元做网站网站代理公司
  • 做投票的网站如何刷seo关键词排名
  • 深圳做外贸网站公司哪家好推广优化厂商联系方式
  • 网站更新后 需要更新 sitemap 吗深圳最新政策消息
  • vi设计的目的厦门seo计费
  • html5+css3网页设计优化关键词的步骤
  • 深圳网站建设大公司好网上接单平台
  • 深圳 网站建设培训百度热门关键词
  • 介绍旅游美食的网站模板免费下载百度上如何做优化网站
  • 晋江网站建设联系电话太原seo外包服务
  • 商城网站建设报价小程序商城
  • 南昌定制网站开发多少钱营销培训课程视频
  • 网站快照优化公司百度咨询
  • 电子商务网站建设与管理实验廊坊seo外包
  • 网站服务器租用报价google play官网入口
  • 大连做网站软件营销推广运营
  • 青岛做企业网站公司网站制作
  • 贵阳网站建设管理杭州seo
  • wordpress修改管理密码错误seo教程网站优化
  • 阿里云网站部署自己可以做网站吗
  • 网店网站开发郑州网站建设公司排行榜
  • 网站推广连接怎么做的优化
  • 衡水做wap网站多少钱企业网站怎么注册