感谢Intel提供这一次机会,我能够很幸运的参与进来,并且提高自己的编程技术。
下面我介绍一下我的工作内容。
一.模型介绍
PaddleOCR是一个基于飞桨深度学习框架的OCR(Optical Character Recognition)工具包,可用于文本检测、文本识别、关键字识别等场景。它支持多种语言文字识别,包括中文、英文、日文、韩文等,并且具有较高的识别准确率和较快的识别速度。PaddleOCR已经在多个行业得到广泛应用,例如金融、医疗、物流等。
以下是使用PaddleOCR的示例代码:
import paddlehub as hub
# 加载PaddleOCR模型
ocr = hub.Module(name='chinese_text_detection_db_server')
# 图片路径
image_path = 'path/to/your/image.jpg'
# 进行文本检测
result = ocr.text_detection(images=[image_path])
# 获取文本框坐标和识别结果
boxes = result[0]['data']
text = result[0]['text']
# 打印文本框坐标和识别结果
for box, txt in zip(boxes, text):
print('文本框坐标:', box)
print('识别结果:', txt)
# 进行文本识别
result = ocr.ocr(images=[image_path], use_gpu=False)
# 获取识别结果
text = result[0]['text']
# 打印识别结果
print('识别结果:', text)
二.我的创新之处。
在实际使用中,尤其是有大量的数据需要识别和OCR文字提取的时候(比如年报和财报),这个时候不断循环调用PaddleOCR的模型会导致速度极慢,严重影响生产效率。
因此我采用了Intel 的 Openvino,将Pth模型转换为IR模型之后推理,利用Core编译加速不少~
三.英特尔架构使用。
core = ov.Core()
## 引用openvino库
device = widgets.Dropdown(
options=core.available_devices + ["AUTO"],
value='AUTO',
description='Device:',
disabled=False,
)
## 转换成Openvino模型
def run_model_download(model_url: str, model_file_path: Path) -> None:
"""
Download pre-trained models from PaddleOCR resources
Parameters:
model_url: url link to pre-trained models
model_file_path: file path to store the downloaded model
"""
archive_path = model_file_path.absolute().parent.parent / model_url.split("/")[-1]
if model_file_path.is_file():
print("Model already exists")
else:
# Download the model from the server, and untar it.
print("Downloading the pre-trained model... May take a while...")
# Create a directory.
utils.download_file(model_url, archive_path.name, archive_path.parent)
print("Model Downloaded")
file = tarfile.open(archive_path)
res = file.extractall(archive_path.parent)
file.close()
if not res:
print(f"Model Extracted to {model_file_path}.")
else:
print("Error Extracting the model. Please check the network.")
# A directory where the model will be downloaded.
det_model_url = "https://storage.openvinotoolkit.org/repositories/openvino_notebooks/models/paddle-ocr/ch_PP-OCRv3_det_infer.tar"
det_model_file_path = Path("model/ch_PP-OCRv3_det_infer/inference.pdmodel")
run_model_download(det_model_url, det_model_file_path)
# Initialize OpenVINO Runtime for text detection.
core = ov.Core()
det_model = core.read_model(model=det_model_file_path)
det_compiled_model = core.compile_model(model=det_model, device_name=device.value)
文字识别结果
总的来说,PaddleOCR是一种高效准确的文字识别模型,它在数据集上表现出色,尤其是经过Intel的Openvino加速之后,锦上添花!再一次感谢Intel主办方提供的这一次机会,我学到了很多,我也学会了很多。