Uncaught (in promise) Error: Argument tensors passed to stack must be a Tensor[] or TensorLike[]
See original GitHub issueTensorFlow.js version
2.0.0
Browser version
Microsoft Edge Version 83.0.478.58 (Official build) (64-bit)
Describe the problem or feature request
Uncaught (in promise) Error: Argument tensors passed to stack must be a Tensor[]
or TensorLike[]
Error occurs every time the model is fit with tensor arrays or by zipping as dataset.
Error Stack :
tensor_util_env.js:125
Uncaught (in promise) Error: Argument tensors passed to stack must be a Tensor[]
or TensorLike[]
at jg (tensor_util_env.js:125)
at stack_ (array_ops.js:134)
at stack (operation.js:45)
at Object.x (array_ops.js:186)
at tape.js:167
at engine.js:425
at t.e.scopedRun (engine.js:436)
at t.e.tidy (engine.js:423)
at engine.js:1005
at s (tape.js:167)
Code to reproduce the bug / link to feature request
<script>
async function trainmodel() {
const model = tf.sequential({
layers:[tf.layers.lstm({units:100,activation:'relu',returnSequences:true,inputShape:[1,1]}),
tf.layers.lstm({units:10,activation:'relu',returnSequences:true}),
tf.layers.dense({units:1})
]
});
const X = tf.tensor3d([0.1,0.4,0.7,0.5],[4,1,1]);
const y = tf.tensor3d([0.05,0.5,0.95,0.8],[4,1,1]);
function onBatchEnd(batch, logs) {
console.log('Loss', logs.acc);
}
model.compile({
optimizer: tf.train.sgd(0.01),
loss: 'meanSquaredError',
metrics: ['accuracy']
});
model.fit(X, y, {
epochs: 3,
callbacks: {onBatchEnd}
}).then(info => {
console.log('Final accuracy', info.history.acc);
});
}
trainmodel();
</script>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
tfjs Error: Argument tensors passed to stack must be a ` ...
I think this is a bug in tf.js namely RNN layers don't accept sequences with just one element (throws an error when fitting)....
Read more >Argument 'a' passed to 'matMul' must be a Tensor, but got ...
It returns a Promise that resolves when the training is done. You may be ... Error: Argument 'indices' passed to 'gather' must be...
Read more >TensorFlow.js API
Pass an array of values to create a vector. tf.tensor([1, 2, 3, 4]).print(); ... The input tensors real and imag must have the...
Read more >4. Image Tensors - Learning TensorFlow.js [Book]
As you might imagine, tf.fill takes a shape, and then the second parameter is the value to fill that shape with. You might...
Read more >uncaught error error: based on the provided shape, [3,3,96, ...
tf-core.esm.js:17 Uncaught (in promise) Error: Based on the provided shape, [256,128], the tensor should have 32768 values but has 29076 at g ...
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
More info:
convertToTensorArray()
, which is a part of the gradient tape mechanism, expects its argument to be an array of Tensor or TensorLike. But for some reason, when input shape of the LSTM is[1, 1]
, i.e., only one temporal step,convertToTensorArray()
receives a single Tensor as argument. If the argument is an Array<Tensor> of length 1, then everything works.Ran into the same issue. It seems that the RNN layer expects an input with at least 2 time steps when training. If that is the case, I think the documentation should mention that.
Why would we need to pass into the RNN layer a sequence with just one element? From my understanding, when using stateful RNN, that might make sense (correct me if I’m wrong).