问题
I want to load a model from an url in node.
This works in the broser:
mobileNet = await tf.loadModel('https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json');
But not in node
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) => {
...
});
The get request returns an Object with a modelTopology and a weightManifest. How could I create a model from it?
回答1:
You need to add this line to your code
global.fetch = require('node-fetch');
tf.loadModel
uses fetch
under the hood. But fetch
is not natively supported in nodeJs. That is why the pollyfill should be imported.
来源:https://stackoverflow.com/questions/52665923/tfjs-node-how-to-load-model-from-url