简体   繁体   English

在本地加载 Tensorflow.js 模型

[英]Load a Tensorflow.js model locally

Currently I am trying to load a json model that I've converted from tensorflow into my tensorflow function.目前,我正在尝试加载一个 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我的 GitHub 存储库目录

However, when I try to add the json file I get the error that loadLayersModel() expects a http request.但是,当我尝试添加 json 文件时,出现 loadLayersModel() 需要 http 请求的错误。 Is there a way to load in my model from the repository?有没有办法从存储库加载我的模型? If not how do I go about this?如果不是,我该怎么做?

Tensorflow.js can't access local files directly (unless you're doing it in Node.js). Tensorflow.js 不能直接访问本地文件(除非你在 Node.js 中这样做)。 Take a look at some of these answers .看看其中一些答案

Looking at the Tensorflow.js API , your options appear to be either:查看Tensorflow.js API ,您的选择似乎是:

  1. Load the model from an HTTP server从 HTTP 服务器加载模型
  2. Load the model from user-selected files from HTML file input elements .从用户从HTML 文件输入元素中选择的文件加载模型。

Replace this line const model = await tf.loadLayersModel('AI-Model/model.json');替换这一行const model = await tf.loadLayersModel('AI-Model/model.json'); by const model = await tf.loadGraphModel('http:AI-Model/model.json');通过const model = await tf.loadGraphModel('http:AI-Model/model.json');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM