本地加载Tensorflow.js模型

2024-03-29 11:10:40 发布

您现在位置:Python中文网/ 问答频道 /正文

目前,我正在尝试加载一个json模型,该模型已从tensorflow转换为tensorflow函数

<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文件时,我得到一个错误,LoadLayerModel()需要一个http请求。有没有办法从存储库加载到我的模型中?如果没有,我该怎么做


Tags: 函数https模型srcjsonnpmnetmodel
2条回答

Tensorflow.js无法直接访问本地文件(除非您在Node.js中这样做)。请看一些these answers

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

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

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

相关问题 更多 >