TFJS-Node:如何从 url 加载模型? [英] TFJS-Node: How to load model from url?

查看:23
本文介绍了TFJS-Node:如何从 url 加载模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从节点中的 url 加载模型.

I want to load a model from an url in node.

这适用于兄弟:

mobileNet = await tf.loadModel('https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json');

但不在节点

错误:在没有获取 polyfill 的情况下,在 Web 浏览器之外不支持 browserHTTPRequest

Error: browserHTTPRequest is not supported outside the web browser without a fetch polyfill

我可以像这样使用节点获取请求:

I can do get request with node like this:

const https = require('https');
https.get(mobileNetUrl, (res) => {
    ...
});

get 请求返回一个带有 modelTopology 和 weightManifest 的对象.我怎么能用它创建一个模型?

The get request returns an Object with a modelTopology and a weightManifest. How could I create a model from it?

推荐答案

你需要在你的代码中加入这一行

You need to add this line to your code

global.fetch = require('node-fetch');

tf.loadModel 在幕后使用 fetch.但是 fetch 在 nodeJs 中不被原生支持.这就是为什么应该导入pollyfill.

tf.loadModel uses fetch under the hood. But fetch is not natively supported in nodeJs. That is why the pollyfill should be imported.

这篇关于TFJS-Node:如何从 url 加载模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆