【问题标题】:Google Machine Learning Engine deployment_uri ErrorGoogle 机器学习引擎部署_uri 错误
【发布时间】:2018-04-20 13:24:13
【问题描述】:

我是机器学习领域的新手,我通过实施 Isolation ForestLocal Outlier Factor 分类器使用 SKlearn 构建了一个模型。现在我正在研究这个模型的部署。我已将训练好的模型导出为 Pickle 文件:

from sklearn.metrics import classification_report, accuracy_score
from sklearn.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor

# define a random state
state = 1

# define the outlier detection method
classifiers = {
    "Isolation Forest": IsolationForest(max_samples=len(X),
                                       contamination=outlier_fraction,
                                       random_state=state),
    "Local Outlier Factor": LocalOutlierFactor(
    n_neighbors = 20,
    contamination = outlier_fraction)
}
from sklearn.externals import joblib
# fit the model
n_outliers = len(Fraud)

for i, (clf_name, clf) in enumerate(classifiers.items()):

    # fit te data and tag outliers
    if clf_name == "Local Outlier Factor":
        y_pred = clf.fit_predict(X)
        # Export the classifier to a file
        joblib.dump(clf, 'model.joblib')
        scores_pred = clf.negative_outlier_factor_
    else:
        clf.fit(X)
        scores_pred = clf.decision_function(X)
        y_pred = clf.predict(X)
        # Export the classifier to a file
        joblib.dump(clf, 'model.joblib')

    # Reshape the prediction values to 0 for valid and 1 for fraudulent
    y_pred[y_pred == 1] = 0
    y_pred[y_pred == -1] = 1

    n_errors = (y_pred != Y).sum()

    # run classification metrics 
    print('{}:{}'.format(clf_name, n_errors))
    print(accuracy_score(Y, y_pred ))
    print(classification_report(Y, y_pred ))

然后我在 Google Cloud 上创建了一个存储桶并将此 model.joblib 上传到该存储桶的文件。 之后,当我尝试创建 ML Engine 版本时,它会引发错误:

字段:version.deployment_uri 错误:部署目录 gs://fdmlmodel_01/ 应包含以下项之一:[saved_model.pb, saved_model.pbtxt]。

由于我是机器学习的新手,我该如何解决这个问题,或者是否有适当的分步教程将此模型部署到 Google Cloud ML Engine。

请帮帮我!

提前致谢!

【问题讨论】:

标签: python machine-learning scikit-learn google-cloud-platform pickle


【解决方案1】:

请参考docs 和官方docs 在 cloud-ml 中构建和部署 scikit-learn 模型。

另存为pickle文件,

import pickle
with open('model.pkl', 'wb') as model_file:
pickle.dump(classifier, model_file)

【讨论】:

  • 当我尝试在 GCP 上创建 ML Model 版本时,它仍然返回:Deployment directory gs://fdmlmodel_01/ is expected to contain exactly one of: [saved_model.pb, saved_model.pbtxt]. 我已将model.pkl 上传到存储桶fdmlmodel_01
  • 建议运行 {gcloud components update} 安装最新的 GCloud,然后按照说明进行操作。使用 gcloud ml-engine 版本创建 {MODEL_VERSION} --model={MODEL_NAME} --origin={MODEL_PATH(PICKLED FILE)} --runtime-version="1.6" --framework="SCIKIT_LEARN"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多