[英]Google Cloud Platform, Ml Engine, No module named sklearn_crfsuite.estimator
I have successfully trained a model scikit on ML Engine. 我已经在ML Engine上成功训练了一个模型scikit。 I can get the model.joblib file from my Cloud Storage bucket and load it, and also get local predictions using gcloud. 我可以从Cloud Storage存储桶中获取model.joblib文件并加载它,还可以使用gcloud获取本地预测。 However I can't create a model version. 但是我无法创建模型版本。
I using sklearn_crfsuite estimator 我使用sklearn_crfsuite估算器
crf = sklearn_crfsuite.CRF(
algorithm='lbfgs',
c1=0.1,
c2=0.1,
max_iterations=2,
all_possible_transitions=True
)
I'm saving the model as described below: 我将按照以下说明保存模型:
model = 'model.joblib'
joblib.dump(crf, model)
my setup.py to train is: 我的setup.py要训练的是:
'''Cloud ML Engine package configuration.'''
from setuptools import setup, find_packages
REQUIRED_PACKAGES = ['joblib==0.13.0',
'sklearn-crfsuite==0.3.6',
'sklearn==0.0'
]
setup(name='trainer',
version='1.0',
packages=find_packages(),
include_package_data=True,
install_requires=REQUIRED_PACKAGES)
I submit package train: 我提交包裹火车:
gcloud ml-engine jobs submit training train_$JOB_NAME \
--runtime-version 1.8 \
--python-version 2.7 \
--job-dir=gs://$BUCKET_NAME/jobs/$JOB_NAME/ \
--package-path= trainer \
--module-name trainer.model \
--region $REGION \
--scale-tier BASIC \
-- \
--train-data-dir=gs://$BUCKET_NAME/dataset \
--job-dir=gs://$BUCKET_NAME/jobs/$JOB_NAME
The model is trained and exported in job-dir, but when to deploy: 该模型经过训练并在job-dir中导出,但是何时部署:
gcloud alpha ml-engine versions create v1 --model teste --origin \
$ORI --python-version 2.7 --runtime-version 1.8 --framework scikit-learn
it reports this error: 它报告此错误:
ERROR: (gcloud.alpha.ml-engine.versions.create) Bad model detected with error: "Failed to load model: Could not load the model: /tmp/model/0001/model.joblib. No module named sklearn_crfsuite.estimator. (Error code: 0)" 错误:(gcloud.alpha.ml-engine.versions.create)检测到错误的模型,并显示错误:“无法加载模型:无法加载模型:/tmp/model/0001/model.joblib。没有名为sklearn_crfsuite.estimator的模块。(错误代码:0)”
Could you verify that you have the directory structure correct? 您可以验证目录结构正确吗?
You do not need to include sklearn in your setup.py, since it is provided by the framework. 您无需在您的setup.py中包含sklearn,因为它是框架提供的。 To avoid confusion, please remove it from REQUIRED_PACKAGES. 为避免混淆,请从REQUIRED_PACKAGES中将其删除。
You can verify that your setup.py is correct by seeing if moving import joblib
to be before the import to sklearn-crfsuite
works 您可以通过查看将import joblib
移到sklearn-crfsuite
之前是否可以运行来验证setup.py是否正确
Make sure setup.py is parallel to trainer (ie one directory up from model.py). 确保setup.py与Trainer平行(即model.py上的一个目录)。 See this GitHub repo for an example: 有关示例,请参见此GitHub存储库:
https://github.com/GoogleCloudPlatform/training-data-analyst/tree/master/blogs/sklearn/babyweight https://github.com/GoogleCloudPlatform/training-data-analyst/tree/master/blogs/sklearn/babyweight
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.