Tensorflow.js使用节点保存模型

Sch*_*tsl 5 javascript node.js async-await tensorflow tensorflow.js

我想使用此功能从node.js保存经过训练的模型

async function tfModelExperiment(model) {
  try {
    let tsModelTraining = await model.save('file:///tmp/my-model-1');
  } 
  catch (error) {
    console.log(error);
  }
}
Run Code Online (Sandbox Code Playgroud)

但是在保存模型时会返回

(节点:23756)UnhandledPromiseRejectionWarning:错误:找不到URL'file:/// tmp / my-model-1'的任何保存处理程序

我发现另一个人正在为这个问题而苦苦挣扎,但是通过解决这个问题

const tf = require('@tensorflow/tfjs');
Run Code Online (Sandbox Code Playgroud)

我已经尝试过将目录更改为我的主目录,但这不能解决问题,也不能以sudo身份运行它,我该怎么办?

软件 我使用Ubuntu的Ubuntu 18.04.1 LTS与故宫安装了最新的TensorFlow.js包(0.13.0)

编辑:

应该注意的是我尝试过

import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-node';
Run Code Online (Sandbox Code Playgroud)

如此处提供的(https://github.com/caisq/tfjs-node),它将返回

TypeError:tf.sequential不是位于ModuleJob.run(internal / loader / ModuleJob.js:94:14)的file:///home/sjors/node.mjs:7:18处的函数

我尝试过:

const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');
Run Code Online (Sandbox Code Playgroud)

返回与UnhandledPromiseRejectionWarning以前相同的错误

Jon*_*nas 11

我现在在 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');
Run Code Online (Sandbox Code Playgroud)