GCP 自定义预测例程无法包含 setup.py 中指定的 json 架构依赖项

GCP Custom Prediction Routine unable to include jsonschema depency specified in setup.py

根据 GCP AI 平台的文档 here,自定义预测例程部署应允许包含 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)"

这里会出什么问题?

事实证明,初始错误 Bad model detected with error: "Failed to load model: Unexpected error when loading the model: 'str' object has no attribute 'decode' (Error code: 0)" 实际上是由模型格式问题引起的。这似乎是 a known issue with TensorFlow Keras (although my TF version is 1.15, the quoted TF version was 2.1.0). Once I used the TensorFlow SavedModel format,错误立即消失了,我也能够按原样将 jsonchema 依赖项包含在 setup.py 文件中。