收藏
回答

上传云函数失败?显示 Unexpected token < in JSON at position

如题。云函数已经经过本地调试,完全没问题。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"
  }
}
最后一次编辑于  2020-06-05
回答关注问题邀请回答
收藏

1 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-06-05

    云函数代码怎么写的,index.js文件

    2020-06-05
    有用
    回复 6
    • Chocolate.Black
      Chocolate.Black
      2020-06-05
      // 云函数入口文件
      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,
        }
      }
      2020-06-05
      回复
    • Chocolate.Black
      Chocolate.Black
      2020-06-05
      还请大佬指教,感谢!
      2020-06-05
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-06-05回复Chocolate.Black
      跟index.js也没关系了,代码我能上传成功。你点击查看详情看看还有没有其它提示
      2020-06-05
      回复
    • Chocolate.Black
      Chocolate.Black
      2020-06-05回复Mr.Zhao
      详情里就只有那一行,已经点了……😂
      2020-06-05
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-06-05回复Chocolate.Black
      要不你试试云端安装依赖
      2020-06-05
      回复
    查看更多(1)
登录 后发表内容
问题标签