在 python 环境中运行良好的简单代码被重写为在节点 js 中运行,但我似乎无法让它工作。
节点 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)
我想知道两件事:
- 如何摆脱压倒一切的错误
- 为什么我得到 TypeError: tf.constant is not a func
我在 Macintosh 10.15.5 Catalina 上运行代码
并且 tf.version 返回以下内容:
{
'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'
}
因为这会返回数据,所以我知道有些事情正在发挥作用。