javascript - 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);
}
任何有关此错误含义的信息将不胜感激。
解决方案
推荐阅读
- typescript - 使用 ts-jest 和 webpack 允许 Jest 识别和解析模块别名需要什么?
- r - 根据列值在数据集中查找行的问题
- jquery - 不要在 Ruby on Rails 6 中连接 Bootstrap 4 和 jQuery
- python-3.x - 在 .Format() 内循环
- javascript - 可以跨计算机查看/使用 localStorage 吗?
- javascript - 使用 Javascript 在 Canvas 中的弧上绘制文本的问题
- javascript - 如何修复“加载资源失败:服务器响应状态为 400 ()”API 获取错误
- r - 消除 R 中除 NA 值外的所有重复项
- mongodb - mongodb:两个字段之间的差异之和
- excel - 将上个月的最后一天添加到 Excel 中的列