在生产环境中运行在 Roboflow 中训练的模型时出现类型错误

问题描述 投票:0回答:1

我可以使用 Google Colab 和 AWS cloud9 测试环境从我训练的 Roboflow 模型中进行推理。

为此,我使用了以下代码:

from roboflow import Roboflow

rf = Roboflow(api_key="xxxxxxxxxxxxxxxxx")
path = "/context/image.jpeg"
project = rf.workspace().project("xxxxxx")
model = project.version(x).model

# infer on a local image
currency_result= model.predict(path, confidence=40).json()```

但是,当我将其投入生产时,出现以下错误:

    [ERROR] TypeError: expected str, bytes or os.PathLike object, not NoneType
Traceback (most recent call last):
  File "/var/lang/lib/python3.8/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/var/lang/lib/python3.8/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/app.py", line 1, in <module>
    from roboflow import Roboflow
  File "/var/lang/lib/python3.8/site-packages/roboflow/__init__.py", line 10, in <module>
    from roboflow.adapters import rfapi
  File "/var/lang/lib/python3.8/site-packages/roboflow/adapters/rfapi.py", line 8, in <module>
    from roboflow.config import API_URL, DEFAULT_BATCH_NAME, DEFAULT_JOB_NAME
  File "/var/lang/lib/python3.8/site-packages/roboflow/config.py", line 51, in <module>
    API_URL = get_conditional_configuration_variable("API_URL", "https://api.roboflow.com")
  File "/var/lang/lib/python3.8/site-packages/roboflow/config.py", line 22, in get_conditional_configuration_variable
    default_path = os.path.join(os.getenv("HOME"), ".config/roboflow/config.json")
  File "/var/lang/lib/python3.8/posixpath.py", line 76, in join
    a = os.fspath(a)

我发现有趣的是,我能够使用

sam local invoke
在cloud9中运行代码,但在生产环境中我得到了上述错误。

python amazon-web-services google-colaboratory aws-cloud9 roboflow
1个回答
0
投票

正如@iurisilvio 指出的,尝试将 HOME 环境变量添加到您的 lambda 配置中。 堆栈跟踪会提示您错误所在,

os.getenv("HOME")
为 None,因此
os.path.join(os.getenv("HOME"), ".config/roboflow/config.json")
会导致错误。

>>> import os
>>> os.path.join(None, "foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen posixpath>", line 76, in join
TypeError: expected str, bytes or os.PathLike object, not NoneType
© www.soinside.com 2019 - 2024. All rights reserved.