javascript - Tensorflow.js 使用节点保存模型
问题描述
我想使用这个函数从 node.js 中保存一个训练有素的模型
async function tfModelExperiment(model) {
try {
let tsModelTraining = await model.save('file:///tmp/my-model-1');
}
catch (error) {
console.log(error);
}
}
但是在保存模型时它会返回
(节点:23756)UnhandledPromiseRejectionWarning:错误:找不到 URL 'file:///tmp/my-model-1' 的任何保存处理程序
我发现另一个人在这个问题上苦苦挣扎,但通过包括
const tf = require('@tensorflow/tfjs');
我已经拥有了,我尝试将目录更改为我的主目录,但这并没有解决问题,也没有将它作为 sudo 运行,我做错了什么?
软件 我使用的是 Ubuntu Ubuntu 18.04.1 LTS,最新的 TensorFlow.js 包 (0.13.0) 安装了 npm
编辑:
应该注意的是,我尝试过
import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-node';
如此处所提供(https://github.com/caisq/tfjs-node),它返回
TypeError: tf.sequential is not a function at file:///home/sjors/node.mjs:7:18 at ModuleJob.run (internal/loader/ModuleJob.js:94:14) at
我试过了:
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');
返回与UnhandledPromiseRejectionWarning
以前相同的错误
解决方案
在 github 上 tfjs 的人的帮助下,我现在开始工作了。
基本上你只需要安装 tfjs-node 依赖项:
npm i @tensorflow/tfjs-node
然后你可以只需要 tfjs 它应该可以工作。
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
model.save('file://./model-1a');
推荐阅读
- python - 运行我的机器人的 python 代码返回了一个语法错误,我不知道错误是什么
- haskell - Haskell 中是否有返回其参数类型(或显示类型的字符串)的函数?
- docker - 构建无堆栈的 docker 镜像
- kubernetes - 如何强制删除 kubernetes pod?
- python - 当我已经通过 pip 安装了模块时,为什么它一直说 ImportError: No module named pydot?
- java - 编译器如何执行信息隐藏和封装?
- php - 使用 MeekroDB 从 TinyMCE 插入 HTML
- laravel - Laravel - 使用不同日期格式播种模型时出错
- python - 为什么 Datatime.now() 的相邻调用在 Windows 上给出相同的结果
- jakarta-ee - 将应用程序部署到 glassfish 4.1.2 时出现 PreDestroy 异常