You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行transmanga漫画翻译项目时遇RuntimeError:无法打开detector.tflite

漫画翻译项目运行报错排查解决

问题场景

  • 基于transmanga仓库开展漫画翻译项目
  • 已执行python build.py并安装pyproject.toml中的依赖库
  • 运行main.py时触发文件找不到错误

报错详情

核心错误:

RuntimeError: Unable to open file at D:\Năm_4\Kì 2\Unemployer\Translate manga\transmanga-main\transmanga\detector.tflite

完整报错堆栈:

Traceback (most recent call last):
  File "D:\Năm_4\Kì 2\Unemployer\Translate manga\transmanga-main\main.py", line 3, in <module>
    transmanga.__main__.main()
  File "D:\Năm_4\Kì 2\Unemployer\Translate manga\transmanga-main\transmanga\__main__.py", line 19, in main
    detector = mp.tasks.vision.ObjectDetector.create_from_options(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python311\Lib\site-packages\mediapipe\tasks\python\vision\object_detector.py", line 234, in create_from_options
    return cls(
           ^^^^
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python311\Lib\site-packages\mediapipe\tasks\python\vision\core\base_vision_task_api.py", line 70, in __init__
    self._runner = _TaskRunner.create(graph_config, packet_callback)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Unable to open file at D:\Năm_4\Kì 2\Unemployer\Translate manga\transmanga-main\transmanga\detector.tflite

问题代码定位

错误根源在transmanga/__main__.py的路径拼接逻辑:

detector = mp.tasks.vision.ObjectDetector.create_from_options(
        mp.tasks.vision.ObjectDetectorOptions(
            base_options=mp.tasks.BaseOptions(
                model_asset_path=pathlib.Path(__file__, os.path.join(os.path.dirname(__file__), "detector.tflite")),
            ),
            score_threshold=0.5,
            running_mode=mp.tasks.vision.RunningMode.IMAGE,
        )
    )

解决方案

1. 确认模型文件存在

  • 检查transmanga目录下是否有detector.tflite文件,若缺失:
    • 从项目仓库获取对应模型文件放入该目录
    • 重新执行python build.py(若脚本包含模型下载逻辑)

2. 修复路径拼接错误

代码同时混用pathlib.Path和os.path.join,导致路径重复拼接,二选一修改即可:

方式一:使用pathlib规范写法

model_asset_path = pathlib.Path(__file__).parent / "detector.tflite"

方式二:使用os.path规范写法

model_asset_path = os.path.join(os.path.dirname(__file__), "detector.tflite")

修改后的完整代码示例:

detector = mp.tasks.vision.ObjectDetector.create_from_options(
        mp.tasks.vision.ObjectDetectorOptions(
            base_options=mp.tasks.BaseOptions(
                model_asset_path=pathlib.Path(__file__).parent / "detector.tflite",
            ),
            score_threshold=0.5,
            running_mode=mp.tasks.vision.RunningMode.IMAGE,
        )
    )

3. 验证路径正确性

可临时添加打印代码确认路径是否有效:

model_path = pathlib.Path(__file__).parent / "detector.tflite"
print(f"模型路径:{model_path}")
print(f"文件是否存在:{model_path.exists()}")

内容的提问来源于stack exchange,提问作者nothing

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 10:04:54