簡體   English   中英

獲取“創建版本失敗。 嘗試在 Google Cloud AI 平台上創建自定義模型時,在 AI 平台上檢測到錯誤模型

[英]Getting 'Create Version failed. Bad model detected with error' on AI platform when trying to create a custom model on Google Cloud AI platform

我正在嘗試在 AI 平台上部署自定義模型。 我已按照 Google 文檔中提到的步驟操作: https : //cloud.google.com/ai-platform/prediction/docs/deploying-models#global-endpoint

保存的模型存儲在 Google Cloud Storage 中,並使用 python 3.7 進行訓練。

這些是用於部署的 gcloud 命令

gcloud ai-platform models create title_topic_custom \
  --regions=europe-west1 --enable_logging
MODEL_DIR="gs://ai_platform_custom/SavedModel"
VERSION_NAME="V3"
MODEL_NAME="title_topic_custom"
CUSTOM_CODE_PATH="gs://ai_platform_custom/SavedModel/my_custom_code-0.1.tar.gz"
PREDICTOR_CLASS="predictor.py.MyPredictor"
gcloud beta ai-platform versions create $VERSION_NAME \
  --model=$MODEL_NAME \
  --origin=$MODEL_DIR \
  --runtime-version=2.1 \
  --python-version=3.7 \
  --machine-type=mls1-c1-m2 \
  --package-uris=$CUSTOM_CODE_PATH \
  --prediction-class=$PREDICTOR_CLASS

執行這些命令后,我收到以下錯誤:

Using endpoint [https://ml.googleapis.com/]
Creating version (this might take a few minutes)......failed.                                                                                                                          
ERROR: (gcloud.beta.ai-platform.versions.create) Create Version failed. Bad model detected with error:  "There was a problem processing the user code: predictor.py.MyPredictor cannot be found. Please make sure (1) prediction_class is the fully qualified function name, and (2) it uses the correct package name as provided by the package_uris: ['gs://ai_platform_custom/SavedModel/my_custom_code-0.1.tar.gz'] (Error code: 4)"

預測器代碼如下:

%%writefile predictor.py
import os
import spacy
import numpy as np
import joblib
import tensorflow as tf
import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords
class MyPredictor(object):
  def __init__(self, model, topic_encoder):
    self._model = model
    self._nlp = spacy.load('en_core_web_sm')
    self._stopwords = stopwords.words('english')
    self._topic_encoder = topic_encoder
  def predict(self, instances, **kwargs):
    inputs = np.asarray(instances)
    inputs_t = [' '.join([i for i in x.split() if i not in self._stopwords]) for x in inputs]
    preprocessed_inputs = [' '.join([i.lemma_ for i in self._nlp(x)]) for x in inputs_t]
    outputs = self._model.predict(preprocessed_inputs)
    return [self._topic_encoder[key] for key in np.argmax(outputs, axis=1)]
  @classmethod
  def from_path(cls, model_dir):
    model_path = os.path.join(model_dir)
    model = tf.keras.models.load_model(model_path)
    topic_encoder = {0:'topic1',1:'topic2',3:'topic3'}
    return cls(model, topic_encoder)

這是安裝文件

from setuptools import setup
setup(
    name='my-custom-code',
    version='0.1',
    install_requires=['nltk','spacy','joblib'],
    scripts=['predictor.py'])

任何解決方法?

嘗試使用PREDICTOR_CLASS="predictor.MyPredictor"而不是"predictor.py.MyPredictor"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM