我正在尝试部署一个自定义的预测例程,该例程对文本进行分类。我训练了一个模型,并在云存储模型目录中提供了.pkl。模型版本创建失败,原因:
ERROR: (gcloud.beta.ai-platform.versions.create) Bad model detected with error: "Failed to load model: User-provided package text_categorizer-0.2.tar.gz failed to install: Command '
['python-default', '-m', 'pip', 'install', '--target=/tmp/custom_lib', '--no-cache-dir', '-b', '/tmp/pip_builds', '/tmp/custom_code/text_categorizer-0.2.tar.gz']' returned non-zero e
xit status 1 (Error code: 0)"
还有什么日志可以检查,以了解更多关于为什么无法加载模型的信息? Predictor类在上传到云存储中的.tar.gz文件中均可用。确保存储桶与创建模型的区域相同。模型文件位于名为model的目录中,而tar.gz文件位于名为textcateg的主目录下。 tar.gz文件包含预测变量python类。
创建版本的命令:
gcloud beta ai-platform versions create ver3 --model text_categorizer --runtime-version 1.13 --python-version 3.5 --origin gs://mdmceml-bucket/textcateg/model/ --package-uris gs://mdmceml-bucket/textcateg/text_categorizer-0.2.tar.gz --prediction-class predictor.GCPPredictor
GCPPredictor的相关代码段::
def __init__(self, le, clf):
"""Stores artifacts for prediction. Only initialized via `from_path`.
"""
self._le = le
self._clf = clf
@classmethod
def from_path(cls, model_dir):
"""Creates an instance of Predictor using the given path.
Loading of the predictor should be done in this method.
Args:
model_dir: The local directory that contains the exported model
file along with any additional files uploaded when creating the
version resource.
Returns:
An instance implementing this Predictor class.
"""
model_path = os.path.join(model_dir, 'category_classifier.pkl')
with open(model_path, 'rb') as f:
model = pickle.load(f)
le_path = os.path.join(model_dir, 'labelencoder.pkl')
with open(le_path, 'rb') as f1:
le = pickle.load(f1)
return cls(le, model)
创建模型版本失败,并显示以下信息:
ERROR: (gcloud.beta.ai-platform.versions.create) Bad model detected with error: "Failed to load model: User-provided package text_categorizer-0.2.tar.gz failed to install: Command '
['python-default', '-m', 'pip', 'install', '--target=/tmp/custom_lib', '--no-cache-dir', '-b', '/tmp/pip_builds', '/tmp/custom_code/text_categorizer-0.2.tar.gz']' returned non-zero e
xit status 1 (Error code: 0)"