Document Layer.apply() kwargs options
See original GitHub issueTensorFlow.js version
tfjs-core-0.15.2
Browser version
N/A
Describe the problem or feature request
When building a Layers model with a preLU, reLU, or leakyReLU layer, optimizing using the core API throws an error.
Code to reproduce the bug / link to feature request
Here’s the code that builds a simple Layers model with an activation function. Using ELU as activation function throws no error (having no activation function works fine, as well). On the contrary, PreLU, reLU, and leakyReLU fail.
const tf = require('@tensorflow/tfjs-node');
const model = tf.sequential();
model.add(tf.layers.dense({ inputDim: 1, units: 1 }));
model.add(tf.layers.leakyReLU()); // Fails
// model.add(tf.layers.prelu()); // Fails
// model.add(tf.layers.reLU()); // Fails
// model.add(tf.layers.elu()); // Works
const xs = tf.tensor2d([[Math.random()], [Math.random()]]);
const ys = tf.tensor2d([[Math.random() + 10], [Math.random() + 10]]);
tf.train.sgd(0.1).minimize(() => model.apply(xs).sub(ys).square().mean());
Output when using prelu:
2019-03-18 15:00:36.251109: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX
/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:107
throw ex;
^
Error: Tensor is disposed.
at Tensor.throwIfDisposed (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tensor.js:284:19)
at Tensor.greater (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tensor.js:585:14)
at grad (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/ops/relu_ops.js:59:23)
at Object.tapeNode.gradient (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:144:45)
at _loop_1 (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tape.js:84:35)
at Object.backpropagateGradients (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tape.js:112:9)
at /home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:363:20
at /home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:91:22
at Engine.scopedRun (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:101:23)
at Engine.tidy (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:90:21)
Output when using reLU:
2019-03-18 15:02:00.429530: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX
/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:107
throw ex;
^
Error: Tensor is disposed.
at Tensor.throwIfDisposed (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tensor.js:284:19)
at Tensor.step (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tensor.js:775:14)
at grad (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/ops/relu_ops.js:17:26)
at Object.tapeNode.gradient (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:144:45)
at _loop_1 (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tape.js:84:35)
at Object.backpropagateGradients (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tape.js:112:9)
at /home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:363:20
at /home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:91:22
at Engine.scopedRun (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:101:23)
at Engine.tidy (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:90:21)
Output when using leakyReLU:
/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:107
throw ex;
^
TypeError: Cannot read property 'values' of undefined
at NodeJSKernelBackend.getInputTensorIds (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-node/dist/nodejs_kernel_backend.js:142:26)
at NodeJSKernelBackend.executeSingleOutput (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-node/dist/nodejs_kernel_backend.js:186:73)
at NodeJSKernelBackend.greaterEqual (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-node/dist/nodejs_kernel_backend.js:429:21)
at environment_1.ENV.engine.runKernel.$a (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/ops/compare.js:89:83)
at /home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:129:26
at Engine.scopedRun (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:101:23)
at Engine.runKernel (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/engine.js:127:14)
at greaterEqual_ (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/ops/compare.js:89:37)
at Object.greaterEqual (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/ops/operation.js:23:29)
at Tensor.greaterEqual (/home/ubuntu/issue/node_modules/@tensorflow/tfjs-core/dist/tensor.js:594:26)
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Proper way to use **kwargs in Python - Stack Overflow
I like to use positional arguments only for required arguments, and kwargs for arguments that may or may not be specified, but it...
Read more >Layer weight regularizers - Keras
Layer weight regularizers. Regularizers allow you to apply penalties on layer parameters or layer activity during optimization. These penalties are summed ...
Read more >tf.keras.layers.Layer | TensorFlow v2.11.0
call(self, inputs, *args, **kwargs) : Called in __call__ after making sure build() has been called. call() performs the logic of applying the layer...
Read more >Folium 0.12.1 documentation
For more advanced tile layer options, use the TileLayer class. ... **kwargs – Additional keyword arguments are passed to Leaflets Map class: ...
Read more >API documentation - gmaps figure
You can use the drawing layer to add lines, markers and polygons to a map: >>> fig = gmaps.figure() >>> drawing = gmaps.drawing_layer(features=[...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just manually verified that this is fixed in https://github.com/tensorflow/tfjs-core/pull/1604 which will come in the next release
1.0.2
by end of week.This means you don’t need to pass
{training: true}
in the next release.Thanks for the feedback and the great bug reproduce @josei !
@caisq Does Python Keras have
training=true
as an argument when calling a layer functionally, or is this specific to TF.js? If specific to TF.js, curious when did this option toapply()
got added? Thanks!