FYI: New way of doing tensor operations inside custom layers

FYI: For when you create your own custom layers (quite low level stuff!) there is a slightly new way to do it which prevents memory leaks and such like:

Old way (if A is an intermediate calculation):

var A = backend.Mul(B,C);

New way:

using A = backend.NewTempTensorFloat(new TensorShape(5,6));

This means the the temporary tensor get’s cleared up from memory and not hanging around. (Then you use backend.NewOutputTensorFloat for the actual output.)

When you do normal tensor operations it’s the same as before.

Hope this helps people! :slightly_smiling_face:

1 Like

Also side note, you’ll notice that now you need to figure out the shape of your output.
You can use utility methods on tensorshape.

TensorShapeHelper.BroadcastShape(a.shape, b.shape)