【问题标题】:Load a Tensorflow.js model locally在本地加载一个 Tensorflow.js 模型
【发布时间】:2021-02-26 00:57:50
【问题描述】:

目前我正在尝试加载一个我已经从 tensorflow 转换到我的 tensorflow 函数的 json 模型。

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js">
</script>
<script>
    //!pip install tensorflowjs;
    // * as tf from '@tensorlowjs/tfjs';
    async function tensorFlow(){
    const model = await tf.loadLayersModel('AI-Model/model.json');

}

tensorFlow()

</script>

Directory of my GitHub Repository

但是,当我尝试添加 json 文件时,我收到 loadLayersModel() 需要 http 请求的错误。有没有办法从存储库中加载我的模型?如果不是,我该怎么办?

【问题讨论】:

    标签: javascript python html json tensorflow


    【解决方案1】:

    Tensorflow.js 无法直接访问本地文件(除非您在 Node.js 中进行)。看看these answers的一些内容。

    查看Tensorflow.js API,您的选择似乎是:

    1. 从 HTTP 服务器加载模型
    2. HTML file input elements 的用户选择的文件中加载模型。

    【讨论】:

      【解决方案2】:

      将此行 const model = await tf.loadLayersModel('AI-Model/model.json'); 替换为 const model = await tf.loadGraphModel('http:AI-Model/model.json');

      【讨论】:

      • 请您用英文写作以吸引更多观众
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多