2

Simple code that works fine in python environment was rewritten to run in node js but I can't seem to get it to work.

The node js code looks like:

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)

I get the following errors when I run this code:

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)

I'd like to know two things:

  1. how to get rid of the overriding errors
  2. why I'm getting the TypeError: tf.constant is not a func

I'm running the code on a Macintosh 10.15.5 Catalina

and tf.version returns the following:

{
 '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'
}

Because this returns data I know that some things are working.

  • I have fixed the divide error and most of the warnings by modifying the code. Apparently tf.divide does not exist and you must use tf.div I only found this error by printing out all the functions supported using: console.dir(JSON.stringify(Object.keys(tf), null, 4)) And I noticed tf.div not tf.divide as the documentation specifies I also set the Environment variable named TF_CPP_MIN_LOG_LEVEL using: export TF_CPP_MIN_LOG_LEVEL=3 – Rodney East Jul 06 '20 at 15:27
  • Code now looks like: `// to get rid of most of the warning measages,set the TF_CPP_MIN_LOG_LEVEL environment level using // export TF_CPP_MIN_LOG_LEVEL=3 const tf = require('@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)` and the errors look like: 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' – Rodney East Jul 06 '20 at 15:29

0 Answers0