0

根据此处的 GCP AI Platform 文档,自定义预测例程部署应允许包含 PyPI 依赖项。我在setup.py脚本中包含了我对 jsonschema 的依赖,如下所示:

from setuptools import setup
from setuptools import find_packages


REQUIRED_PACKAGES = ['jsonschema']

setup(
    name='custom_code',
    version='1.0.2',
    scripts=['predictor.py', 'preprocess.py'],
    install_requires=REQUIRED_PACKAGES,
    packages=find_packages(),
    include_package_data=True
)

但在部署时收到此错误消息:

ERROR: (gcloud.beta.ai-platform.versions.create) Create Version failed. Bad model detected with error:  "Failed to load model: Unexpected error when loading the model: 'str' object has no attribute 'decode' (Error code: 0)"

指定这样的版本时,同样的错误仍然存​​在REQUIRED_PACKAGES = ['jsonschema==3.2.0']。然后我使用了一个较低的版本:

from setuptools import setup
from setuptools import find_packages


REQUIRED_PACKAGES = ['jsonschema==3.0.0']

setup(
    name='custom_code',
    version='1.0.2',
    scripts=['predictor.py', 'preprocess.py'],
    install_requires=REQUIRED_PACKAGES,
    packages=find_packages(),
    include_package_data=True
)

但现在出现此错误:

ERROR: (gcloud.beta.ai-platform.versions.create) Create Version failed. Bad model detected with error:  "Failed to load model: Unexpected error when loading the model: problem in predictor - DistributionNotFound: The 'jsonschema' distribution was not found and is required by the application (Error code: 0)"

这里有什么问题?

4

1 回答 1

2

事实证明,最初的错误Bad model detected with error: "Failed to load model: Unexpected error when loading the model: 'str' object has no attribute 'decode' (Error code: 0)"实际上是由模型格式问题引起的。这似乎是TensorFlow Keras的一个已知问题(虽然我的 TF 版本是 1.15,但引用的 TF 版本是 2.1.0)。一旦我使用了TensorFlow SavedModel 格式,错误立即消失了,我还能够在setup.py文件中包含 jsonchema 依赖项。

于 2020-11-20T16:08:03.840 回答