【发布时间】:2020-04-30 08:55:42
【问题描述】:
我的模型 (tf.keras.Sequential) 是在 Python 中训练的,我使用 tfjs.converters.save_keras_model() 将其转换为 TF.js 层格式。 我在 cmd 中使用“http-server”在文件夹中创建了一个服务器(其中包含 *.bin 文件和一个“model.json”)。 之后,我运行这段代码来加载模型:
(async () => {
const model = await tf.loadLayersModel('http://127.0.0.1:8080/model.json');
console.log('done');
})();
这对我不起作用,这 3 个错误出现在我的控制台中:
Access to fetch at 'http://127.0.0.1:8080/model.json' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
GET http://127.0.0.1:8080/model.json net::ERR_FAILED
Uncaught (in promise) Error: Request for http://127.0.0.1:8080/model.json failed due to error: TypeError: Failed to fetch
at tf.min.js:2
我不知道如何解决它。
【问题讨论】:
标签: javascript tensorflow tensorflow.js