gpt4 book ai didi

google-cloud-platform - 将数据发送到 Google Cloud ML 自定义预测例程时出现未知错误

转载 作者:行者123 更新时间:2023-12-02 18:00:27 24 4
gpt4 key购买 nike

我正在尝试在 AI Platform 上编写自定义 ML 预测例程,以从客户端获取文本数据,进行一些自定义预处理,将其传递到模型中,然后运行模型。我能够成功地将这段代码打包并部署到谷歌云上。但是,每次我尝试从 node.js 向其发送请求时,都会返回 data: { error: '预测失败:未知错误。' },

这是我的相关自定义预测例程代码。请注意,我将 instances 设置为客户端中的文本,然后在自定义预测例程中对其进行标记和预处理。

def __init__(self, model, session, saver, dictionary):
self.model = model
self.sess = session

@classmethod
def from_path(cls, model_dir):
m = Model(learning_rate=0.1)
session = tf.Session()
session.run(tf.global_variables_initializer())
session.run(tf.local_variables_initializer())
saver = tf.train.Saver(max_to_keep=0)
saver.restore(session, (os.path.join(model_dir, 'model.ckpt')))
return cls(m, session)

def predict(self, instances, **kwargs):
utterance = nltk.word_tokenize(instances)
utterance = self.preprocess_utterance(utterance)

preds = self.sess.run([self.model['preds'], feed_dict={'input_data': utterance)
return preds

这是我的 Node.js 代码:

   text_string = "Hello how are you?"
google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
console.log('Authentication failed because of ', err);
return;
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
var scopes = ['https://www.googleapis.com/auth/cloud-platform'];
authClient = authClient.createScoped(scopes);
}
var request = {
name: "projects/" + projectId + "/models/classifier",
resource: {"instances": [message_string]},

// This is a "request-level" option
auth: authClient
};

machinelearning.projects.predict(request, function (err, result) {

console.log(result)

if (err) {
console.log(err);
} else {
console.log(result);
res.status(200).send('Hello, world! This is the prediction: ' + JSON.stringify(result)).end();
}
});
});

在此代码中,我只是将文本发送到谷歌云模型。请求正文是:body: '{"instances":["你好,你好吗?"]}',

有人知道它失败的原因吗?

如果没有,那么有人知道我如何调试它吗?未知的错误消息根本没有用。

编辑:

这是带有 --all 选项的 saved_model_cli 的输出。

signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['length_input'] tensor_info:
dtype: DT_INT32
shape: ()
name: Placeholder_3:0
inputs['seqlen'] tensor_info:
dtype: DT_INT32
shape: (-1)
name: Placeholder_2:0
inputs['indicator'] tensor_info:
dtype: DT_INT32
shape: (-1, 2)
name: Placeholder_1:0
inputs['input_data'] tensor_info:
dtype: DT_INT32
shape: (-1, -1)
name: Placeholder:0
inputs['y'] tensor_info:
dtype: DT_INT32
shape: (-1, -1)
name: Placeholder_4:0
The given SavedModel SignatureDef contains the following output(s):
outputs['preds'] tensor_info:
dtype: DT_INT32
shape: (-1, -1)
name: Cast:0
Method name is: tensorflow/serving/predict

基于此,我应该提供这本字典作为输入,但它不起作用。

{“实例”:[ {
“输入数据”:[138,30,66],
“长度输入”:1,
“指标”:[[0, 0]],
“序列”:[3],
“y”:[138,30,66]
}
]}

最佳答案

我发现了这个问题。问题不在于输入数据的格式。相反,它是在 NLTK 中。 NLTK.word_tokenize 引发错误,因为它没有进行标记化所需的数据。我必须将数据上传到 Google Cloud 或使用不需要任何数据文件的标记化方法来解决此问题。

我不知道为什么这个 Google Cloud 自定义预测例程软件不告诉用户正在发生的错误,但通过我的努力,只要出现问题,它总是只返回未知错误 。如果我准确地知道错误是什么,这将是一个简单的修复。

关于google-cloud-platform - 将数据发送到 Google Cloud ML 自定义预测例程时出现未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56604407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com