Tfjs node tfjs节点tf.constant不是函数错误

Tfjs node tfjs节点tf.constant不是函数错误,tfjs-node,Tfjs Node,在python环境中运行良好的简单代码被重写为在NodeJS中运行,但我似乎无法让它正常工作 节点js代码如下所示: const tf = require('@tensorflow/tfjs-node'); var x= tf.constant([10, 20, 30]) var y= tf.constant([ 2, 3, 5]) var z= tf.divide(x, y) 运行此代码时,我遇到以下错误: Overriding the gradient for 'Max' Overr

在python环境中运行良好的简单代码被重写为在NodeJS中运行,但我似乎无法让它正常工作

节点js代码如下所示:

const tf = require('@tensorflow/tfjs-node');

var x= tf.constant([10, 20, 30])
var y= tf.constant([ 2, 3, 5])  
var z= tf.divide(x, y)
运行此代码时,我遇到以下错误:

Overriding the gradient for 'Max'
Overriding the gradient for 'OneHot'
Overriding the gradient for 'PadV2'
Overriding the gradient for 'SpaceToBatchND'
Overriding the gradient for 'SplitV'
2020-07-01 13:31:52.548282: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-07-01 13:31:52.573722: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x104718410 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-01 13:31:52.573765: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
/Users/rodney/Desktop/node_code/ccx_MultiTool/playground/test18.js:3
var x= tf.constant([10, 20, 30])
          ^
TypeError: tf.constant is not a function
    at Object.<anonymous> (/Users/rodney/Desktop/node_code/ccx_MultiTool/playground/test18.js:3:11)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
(base)

因为这会返回数据,所以我知道有些东西正在工作。

我通过修改代码修复了除法错误和大多数警告。显然,tf.divide不存在,您必须使用tf.div。我只是通过使用:console.dir(JSON.stringify(Object.keys(tf),null,4))打印出所有支持的函数才发现了这个错误我注意到tf.div不是tf.divide,因为文档指定了我还使用export-tf\u-CPP\u-MIN\u-LOG\u-LEVEL=3Code设置了名为tf\u-CPP\u-MIN\u-LOG\u-LEVEL的环境变量:export-tf\u-CPP\u-MIN\u-LOG\u-LEVEL=3Code现在看起来是这样的:
//若要消除大多数警告措施,请使用//export-tf\u-CPP\u-MIN\u-LOG\u-LOG\u-LOG\u-LOG\u-LEVEL=3 const('@tensorflow/tfjs node');//console.dir(JSON.stringify(Object.keys(tf),null,4))var x=[10,20,30]var y=[2,3,5]var z=tf.div(x,y)//console.log('z:',z)tf.print(z)
错误如下:覆盖“Max”的渐变覆盖“OneHot”的渐变覆盖“PadV2”的渐变覆盖“SpaceToBatchND”的渐变覆盖“SplitV”的渐变
{
 'tfjs-core': '2.0.1',
  'tfjs-backend-cpu': '2.0.1',
  'tfjs-backend-webgl': '2.0.1',
  'tfjs-data': '2.0.1',
  'tfjs-layers': '2.0.1',
  'tfjs-converter': '2.0.1',
  tfjs: '2.0.1',
  'tfjs-node': '2.0.1'
}