no data found for this tensor
See original GitHub issueFrom @riatzukiza on March 18, 2018 18:52
Error
I was struggling with a memory leak, then I fix the leak, and I start getting this error.
bundle.js:14641 Uncaught (in promise) Error: WebGL backend: No data found for this tensor. Did you change your backend in the middle of the program? New backends can't use Tensors created with previous backends
at MathBackendWebGL.throwIfNoData (bundle.js:14641)
at MathBackendWebGL.readSync (bundle.js:14048)
at MathBackendWebGL.<anonymous> (bundle.js:14093)
at step (bundle.js:13922)
at Object.next (bundle.js:13903)
at fulfilled (bundle.js:13894)
at <anonymous>
Code
I am rendering data to a canvas, so I have to call data every frame.
deeplearn logic
Logic to the implementation of conways game of life.
var kernel = dl.reshape(dl.tensor2d([
[1, 1, 1],
[1, 0, 1],
[1, 1, 1]
]), [3, 3, 1, 1]);
var state0Tensor = dl.randomUniform([H, W]).greater(dl.scalar(0.5, "float32"));
var state = dl.variable(dl.cast(dl.reshape(state0Tensor, [1, H, W, 1]), "float32"));
var step = (function step$() {
var newState = dl.tidy((() => {
var neighbors = dl.conv2d(state, kernel, [1, 1, 1, 1], "same");
var survive = dl.logicalAnd(dl.equal(state, dl.scalar(1, "float32")), dl.equal(neighbors, dl.scalar(2, "float32"))),
born = dl.equal(neighbors, dl.scalar(3, "float32"));
return dl.cast(dl.logicalOr(survive, born), "float32");
}));
state.assign(newState);
newState.dispose();
return state;
});
rendering
Then I itterate over every element of tensor.data()
, the error points at
return state.data().then(((d) => {
^
render(canvas = this.canvas, state = this.state, shape = this.shape, imageData = this.imageData, ctx = this.ctx) {
if (!(running__QUERY)) {
return false;
};
var height = shape[0],
width = shape[1];
return state.data().then(((d) => {
var j = 0,
k = 0;
for (var i = 0; i < (width * height); ++(i)) {
j = (i * 4);;
this._renderCell(d[i], j, imageData)
};
return ctx.putImageData(imageData, 0, 0);
}));
}
Copied from original issue: tensorflow/tfjs-core#865
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:14 (1 by maintainers)
Top Results From Across the Web
Why tensor board is showing "no scalar data is found"?
The tensorboard is launching before the model training starts, and says nothing is present. Then, if you try to re-run the cell, ...
Read more >Reading data - TensorFlow
Reading data. There are three main methods of getting data into a TensorFlow program: Feeding: Python code provides the data when running each...
Read more >tf.data: Build TensorFlow input pipelines
The tf.data API enables you to build complex input pipelines from simple, reusable pieces. For example, the pipeline for an image model might...
Read more >torch.sparse — PyTorch 1.13 documentation
Only values and indices of non-zero elements are stored in this case. ... Constructing a new sparse COO tensor results a tensor that...
Read more >torch_geometric.data — pytorch_geometric documentation
Add additional arguments to `data`: data.train_idx = torch.tensor([. ... KeyError – If the tensor corresponding to the input TensorAttr was not found.
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
Ahhh yes! That makes a lot of sense. Basically what happens is you deep copy the tensor, the data ID also gets copied, but TensorFlow.js doesn’t know about it.
So the first Tensor gets cleaned up, destroying that data bucket (keyed by data ID). The next time you access the second data bucket we don’t know about it.
Just FYI, you can use “.clone()” to clone a Tensor. It will return a new Tensor, however clone() is extremely cheap. Under the covers we create another “shell” Tensor pointing to the same data ID.
Nice job finding that!
On Mon, Apr 30, 2018 at 8:39 AM, Grimmer notifications@github.com wrote:
Since this issue, we’ve done global tracking of tensors, as well as transferring tensors between backends, so this error is likely outdated.