Google Cloud Custom预测例程:{u'error':u'预测失败:未知错误。'}

时间:2019-08-20 14:11:12

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

我正在尝试在GC中部署自定义预测变量。我按照Google提供的示例进行了开发,并添加了一些额外的类。

我已经成功创建了模型的一个版本,并且以前我已经在本地测试了该代码,并且可以正常工作。

但是,当我尝试请求在线预测时,会返回以下错误:

{u'error':u'预测失败:未知错误。'} 追溯(最近一次通话):   文件“ request_prediction.py”,第60行,在     引发RuntimeError(response ['error']) RuntimeError:预测失败:未知错误。

为简化此问题,我将预测函数简化为一个简单的代码,该代码仅接收数据并返回相同的数据,并且还返回相同的错误。

我试图在预测函数中添加一些日志,但是在Stackdriver中,日志没有出现任何日志。

...

import os
from sklearn.externals import joblib
import pickle
import numpy as np

# Imports the Google Cloud client library
from google.cloud import logging


class rf_predictor(object):
 def __init__(self, preprocessor, manage_models, model_dir):
   #self._model = model
   self._preprocessor = preprocessor
   self._mm = manage_models
   self._model_dir = model_dir

   print("Init ")

 def predict(self, instances, **kwargs):
    # Instantiates a client
   logging_client = logging.Client()
   # The name of the log to write to
   log_name = 'predictor-log'
   # Selects the log to write to
   logger = logging_client.logger(log_name)
   logger.log_text("Prueba Log")
   print('Logged: {}'.format("Prueba Log"))

   print("Predict")
   print(instances) #DELETE

   return instances.tolist()



 @classmethod
 def from_path(cls, model_dir):

   #model_path = os.path.join(model_dir, 'model.joblib')
   #model = joblib.load(model_path)

   preprocessor_path = os.path.join(model_dir, 'preprocessor.pkl')
   with open(preprocessor_path, 'rb') as f:
     preprocessor = joblib.load(f)

   preprocessor_path = os.path.join(model_dir, 'manage_models.pkl')
   with open(preprocessor_path, 'rb') as f:
     manage_models = joblib.load(f)

   return cls(preprocessor, manage_models, model_dir)

关于如何调试代码并添加一些日志的任何想法?

这是我用于预测变量的教程: https://cloud.google.com/ml-engine/docs/custom-prediction-routines

这对于日志记录: https://cloud.google.com/logging/docs/reference/libraries#client-libraries-install-python

0 个答案:

没有答案