如题。云函数已经经过本地调试,完全没问题。json文件我也已经检验过了,格式没有问题(更正:只检验了package那两个json文件,node_modules里的文件太多还没来得及……,但按理说应该没问题,本地调试的时候没有出错)。但是上传一直失败。求助各位大神,急
ps. 我用的是上传并部署:所有文件
其中一个json文件如下:
{
"name": "LSTMModelInfer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@tensorflow/tfjs-node": "^1.7.4",
"typescript": "^3.9.5",
"wx-server-sdk": "^2.1.0"
}
}
云函数代码怎么写的,index.js文件
const cloud = require('wx-server-sdk')
// 导入tfjs-node依赖
const tf = require('@tensorflow/tfjs-node')
cloud.init({
env: 'hartest-b7yls',
traceUser: true,
})
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
//获取云存储中模型文件的临时URL地址
const fileList = ['cloud://hartest-b7yls.6861-hartest-b7yls-1302325027/LSTMmodel/model.json']
const filelist_urls = await cloud.getTempFileURL({ fileList: fileList })
console.log(filelist_urls)
const Model_file = filelist_urls.fileList[0]['tempFileURL']
//调用tfjs中API加载模型
const model = await tf.loadLayersModel(Model_file)
//模拟输入数据
// const input = [tf.zeros([1, 128, 6])]
var data = event.data;
const input = tf.tensor3d(data);
//推理并打印
var prediction = model.predict(input);
var result = prediction.arraySync();
result = result[0];
var max_value = Math.max.apply(Math, result);
var index = result.indexOf(max_value);
var action = '';
if(index == 0){
action = "站立";
}else if(index == 1){
action = "扩胸";
}else if(index == 2){
action = "深蹲";
}else if(index == 3){
action = "俄罗斯转体"
}else if(index == 4){
action = "仰卧起坐"
}
return await {
input:input,
action:action,
}
}