代码之家  ›  专栏  ›  技术社区  ›  willbattel

Google ML引擎在线预测请求没有响应的预测结果

  •  0
  • willbattel  · 技术社区  · 7 年前

    ML引擎正在接收我的预测请求,但我没有在回调函数中获取预测结果。

    StackDriver显示正在成功发送的请求:

    这是我当前的云函数,它通过 data.imagedata 传递base64编码的图像数据,我已经通过复制输出并从我的PC运行预测请求来验证它是有效的图像编码。

    const google=需要(“googleapis”); 如果(data.imagedata){ google.auth.getapplicationdefault((err,authclient)=>。{ 预测:“错误” if(authclient.createScopedRequired&authclient.createScopedRequired()){ authclient=authclient.createscoped(['https://www.googleapis.com/auth/cloud platform']); //创建经过身份验证的ML引擎客户端 版本:“v1”, 名称:`项目/我的项目名称/模型/我的模型名称`, 实例:[“B64”:data.imagedata] },(错误,结果)=>。{ 如果(错误){ } 返回{ } }
    
    
    
    
    资源:{
    实例:[“B64”:data.imagedata]
    
    

    但他们的表现似乎都一样。

    results.predictions总是空的,当我字符串化时results

    Firebase Cloud Functions console

    Stackdriver logs

    您还可以在ML发动机型号仪表板上看到,Last use time当我调用云函数时进行反射。

    My model is being called

    以下是我为设置云功能所遵循的指南:https://github.com/GoogleCloudPlatform/ml-functions-helpdesk/blob/master/functions/index.js

    data.imageData

    const functions = require('firebase-functions');
    const {google} = require('googleapis');
    
    exports.analyzeDetection = functions.https.onCall((data, context) => {
        if (data.imageData) {
            // Auth
            google.auth.getApplicationDefault((err, authClient) => {
                if (err) {
                    console.error("getApplicationDefault err " + err);
                    return {
                        prediction: "error"
                    }
                }
    
                //[START ml_engine_auth]
                if (authClient.createScopedRequired && authClient.createScopedRequired()) {
                    // https://developers.google.com/identity/protocols/googlescopes#mlv1
                    authClient = authClient.createScoped(['https://www.googleapis.com/auth/cloud-platform']);
                }
    
                //Create authenticated ml engine client
                var ml = google.ml({
                    version: 'v1',
                    auth: authClient
                });
                //[END ml_engine_auth]
    
                // Prediction
                ml.projects.predict({
                    name: `projects/my_project_name/models/my_model_name`,
                    resource: {
                        instances: [{"b64": data.imageData}]
                    }
                }, (err, result) => {
    
                    // The problem is that result is always null
    
                    if (err){
                        console.error('ERROR ', err);
                        return {
                            prediction: "error"
                        }
                    }
                    return {
                        prediction: "add this after the prediction requests are working"//result.predictions[0].predicted
                    }
                });
            });
        }
    });
    

    my_project_namemy_model_name

    name: 'projects/my_project_name/models/my_model_name',
    resource: {
        instances: [{"image_bytes": {"b64": data.imageData}, "key": "0"}]
    }
    

    name: 'projects/my_project_name/models/my_model_name',
    resource: {
        name: 'projects/my_project_name/models/my_model_name',
        instances: [{"b64": data.imageData}]
    }
    

    1 回复  |  直到 7 年前
        1
  •  1
  •   willbattel    7 年前

    经过进一步的挖掘、试验、错误等。我已经确定预测结果存储在 results.data results result.data.predictions[0].scores result.data.predictions[0].prediction data