【问题标题】:Error loading model.json Tensorflow.js, IOHandler provided does not have the `load` method implemented加载 model.json Tensorflow.js 时出错,提供的 IOHandler 没有实现 `load` 方法
【发布时间】:2020-09-01 19:27:22
【问题描述】:

当我尝试在我的网络应用程序上加载我的训练模型时出现以下错误,从路径正确到达 json(我尝试使用 console.log 打印并且没关系),似乎问题是当 tf.loadLayers 尝试加载它时......

Vue 应用代码

  import * as tf from '@tensorflow/tfjs';

  export default {
    data(){
      return {
        modelJSON: require('../model/jsmodel/model.json'),
      }
    },
  mounted(){
    this.loadModel();
  },
  methods: {
      async loadModel(){
        this.model = await tf.loadLayersModel(this.modelJSON)
      },
...

错误

models.js?411e:207 Uncaught (in promise) Error: Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.
    at loadLayersModelFromIOHandler (models.js?411e:207)
    at loadLayersModelInternal (models.js?411e:190)
    at Module.loadLayersModel (exports.js?79b0:220)
    at _callee$ (SingleTweet.vue?b47c:40)
    at tryCatch (runtime.js?96cf:63)
    at Generator.invoke [as _invoke] (runtime.js?96cf:293)
    at Generator.eval [as next] (runtime.js?96cf:118)
    at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
    at _next (asyncToGenerator.js?1da1:25)
    at eval (asyncToGenerator.js?1da1:32)

【问题讨论】:

  • 我遇到了完全一样的问题,我试过用webpack导入ES6,还是不行,我试试看源码。

标签: javascript tensorflow keras tensorflow.js


【解决方案1】:

我检查了源代码,看起来使用 ES6 或 CommonJS 导入的模型的静态文件 manifesto json 中的正确处理程序未实现,因此作为一种解决方法,它通过 http 对我有用,您可以将模型放置到存储或启动本地服务器并在浏览器中为您打开应用程序的页面禁用 CORS。我觉得issue可以在github项目上打开。

  1. 安装http服务器,例如

    npm install http-server -g

  2. 启动您的开发服务器

    npm 运行开发

  3. 启动服务器以提供模型文件夹中的文件

    http-服务器

  4. 在我的例子中,将 this.modelJSON 更改为 JSON 文件的路径

    const modelJSON = 'http://127.0.0.1:8087/model.json'

  5. 禁用CORS以允许跨域请求,有一个插件可以做到。

可以放置模型,例如到 CloudStorage 或任何其他具有静态数据的服务器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 2021-05-19
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多