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

[报错解决] 运行MATCHA时需要在线下载Arial.TTF字体,但是无法连接huggingface

一、报错详情

requests.exceptions.ConnectTimeout:(MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): 
Max retries exceeded with url: /ybelkada/fonts/resolve/main/Arial.TTF (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f5295722ce0>, 
'Connection to huggingface.co timed out. (connect timeout=10)'))"), '(Request ID: a5b5b41d-c258-46b6-8e40-0200bc4cb62b)')The above exception was the direct cause of the following exception:Traceback (most recent call last):File "/MATCHA/workdir/matcha_test.py", line 11, in <module>inputs = processor(images=image, text="Is the sum of all 4 places greater than Laos?", return_tensors="pt")File "/miniconda3/lib/python3.10/site-packages/transformers/models/pix2struct/processing_pix2struct.py", line 109, in __call__encoding_image_processor = self.image_processor(File "/miniconda3/lib/python3.10/site-packages/transformers/image_processing_utils.py", line 552, in __call__return self.preprocess(images, **kwargs)File "/miniconda3/lib/python3.10/site-packages/transformers/models/pix2struct/image_processing_pix2struct.py", line 437, in preprocessimages = [File "/miniconda3/lib/python3.10/site-packages/transformers/models/pix2struct/image_processing_pix2struct.py", line 438, in <listcomp>render_header(image, header_text[i], font_bytes=font_bytes, font_path=font_path)File "/miniconda3/lib/python3.10/site-packages/transformers/models/pix2struct/image_processing_pix2struct.py", line 169, in render_headerheader_image = render_text(header, **kwargs)File "/miniconda3/lib/python3.10/site-packages/transformers/models/pix2struct/image_processing_pix2struct.py", line 128, in render_textfont = hf_hub_download(DEFAULT_FONT_PATH, "Arial.TTF")File "/miniconda3/lib/python3.10/site-packages/huggingface_hub/utils/_deprecation.py", line 101, in inner_freturn f(*args, **kwargs)File "/miniconda3/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fnreturn fn(*args, **kwargs)File "/miniconda3/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1240, in hf_hub_downloadreturn _hf_hub_download_to_cache_dir(File "/miniconda3/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1347, in _hf_hub_download_to_cache_dir_raise_on_head_call_error(head_call_error, force_download, local_files_only)File "/miniconda3/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1857, in _raise_on_head_call_errorraise LocalEntryNotFoundError(
huggingface_hub.utils._errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.

二、报错分析

        代码运行过程中需要从huggingface上下载“/ybelkada/fonts/resolve/main/Arial.TTF”,但是由于我是在服务器上运行项目,所以无法连接huggingface,导致连接超时报错。

具体导致报错的代码是:

 File "/miniconda3/lib/python3.10/site-packages/transformers/models/pix2struct/image_processing_pix2struct.py", line 128, in render_textfont = hf_hub_download(DEFAULT_FONT_PATH, "Arial.TTF")

三、问题解决

进入上述报错位置(image_processing_pix2struct.py)后,发现代码逻辑是:

    if font_bytes is not None and font_path is None:font = io.BytesIO(font_bytes)elif font_path is not None:font = font_pathelse:font = hf_hub_download(DEFAULT_FONT_PATH, "Arial.TTF")font = ImageFont.truetype(font, encoding="UTF-8", size=text_size)

所以问题根源在于font_path == None。

经过逐层向上搜寻,发现font_path赋值位置

File "/miniconda3/lib/python3.10/site-packages/transformers/models/pix2struct/image_processing_pix2struct.py", line 438, in <listcomp>render_header(image, header_text[i], font_bytes=font_bytes, font_path=font_path)
font_path = kwargs.pop("font_path", None)
if isinstance(header_text, str):header_text = [header_text] * len(images)images = [render_header(image, header_text[i], font_bytes=font_bytes, font_path=font_path)for i, image in enumerate(images)]

但是打印kwargs发现是一个空字典,所以修改config.json文件并无法传入font_path参数,最终直接原地修改,Arial.ttf要直接从huggingface下载然后传到服务器上。

font_path = kwargs.pop("font_path", None)if font_path == None:font_path = "YOUR_Arial.ttf_PATH"if isinstance(header_text, str):header_text = [header_text] * len(images)images = [render_header(image, header_text[i], font_bytes=font_bytes, font_path=font_path)for i, image in enumerate(images)]

http://www.lryc.cn/news/446350.html

相关文章:

  • B-树(不是B减树)原理剖析(1)
  • 【shell脚本8】Shell脚本学习--其他
  • 《深度学习》ResNet残差网络、BN批处理层 结构、原理详解
  • javadoc:jdk 9通过javadoc API读取java源码中的注释信息(comment)
  • nordic使用FDS保存数据需要注意的地方
  • docker-compose集群(单机多节点)环境搭建与使用
  • 从静态多态、动态多态到虚函数表、虚函数指针
  • 用 Pygame 实现一个乒乓球游戏
  • 基于大数据可视化的化妆品推荐及数据分析系统
  • Java项目实战II基于Java+Spring Boot+MySQL的汽车销售网站(文档+源码+数据库)
  • 数学基础 -- 微积分最优化之一个最简单的例子
  • kubernetes K8S 结合 Istio 实现流量治理
  • Selenium with Python学习笔记整理(网课+网站持续更新)
  • 1.随机事件与概率
  • Redis结合Caffeine实现二级缓存:提高应用程序性能
  • 【LLM】Ollama:本地大模型 WebAPI 调用
  • SpringBoot集成阿里easyexcel(二)Excel监听以及常用工具类
  • 使用ELK Stack进行日志管理和分析:从入门到精通
  • 前端框架对比与选择
  • Springboot jPA+thymeleaf实现增删改查
  • 【YashanDB知识库】yashandb执行包含带oracle dblink表的sql时性能差
  • 效率工具推荐 | 高效管理客服中心知识库
  • 综合实验1 利用OpenCV统计物体数量
  • [Redis][主从复制][上]详细讲解
  • 【算法】leetcode热题100 146.LRU缓存. container/list用法
  • [论文总结] 深度学习在农业领域应用论文笔记13
  • 《Detection of Tea Leaf Blight in Low-Resolution UAV Remote Sensing Images》论文阅读
  • 低代码BPA(业务流程自动化)技术探讨
  • 开闭原则(OCP)
  • Unity之 TextMeshPro 介绍