首页 > 解决方案 > GCP AutoML Edge 模型在生产服务器上引发输入错误,但在本地环境中却没有

问题描述

我最近一直在使用 GCP 来训练对象检测模型。我将模型导出为 Tensorflow.js 包,以便在我的 react 应用程序上运行客户端。我已经用相同的数据训练了 5 个不同的模型。所有 5 个模型都在 localhost 上完美运行,但是当部署到应用引擎 3 时,模型在进行预测时抛出了以下错误。

Error: Expected len(indices) == tensor.shape[0], but saw: 0 vs. 1
    at e.value (tensor_array.ts:254)
    at control_executor.ts:199
    at u (runtime.js:63)
    at Generator._invoke (runtime.js:293)
    at Generator.next (runtime.js:118)
    at r (asyncToGenerator.js:3)
    at s (asyncToGenerator.js:25)
    at asyncToGenerator.js:32
    at new Promise (<anonymous>)
    at asyncToGenerator.js:21

以下代码是我用来加载模型并使用该模型运行预测的代码

const [modelLoaded, setModelLoaded] = useState(false);
const [modelUrl, setModelUrl] = useState("");
const [model, setModel] = useState(null);

const loadModel = async () => {
    if(!modelLoaded){
        setModelLoaded(true);
        if(process.env.REACT_APP_API_URL != "http://localhost:8080") {
            setModelUrl(process.env.REACT_APP_API_URL);
        } else {
            setModelUrl("http://localhost:3000")
        }

        const loadedModel = await automl.loadObjectDetection(modelUrl + "/model/model.json");
        setModel(loadedModel);
    }
}

const makePrediction = async (imageData) => {
    const options = {score: 0.5, iou: 0.5, topk: 1};
    return await model.detect(imageData, options);
}

任何有关此错误含义的信息将不胜感激。

标签: javascriptgoogle-cloud-platformgoogle-cloud-automl

解决方案


推荐阅读