Sparse input optimization

Hello !
I’m developping a Neural Network for an embarqued system, that needs to make predictions in real time, so as fast as possible.

My current network has huge input size (n = 1 000 000 entries), but most of them are empy, I would say that there is in average 1000 entries not null.
Would there be a way that my first layer only do the multiplication on non null entries, knowing that I have a list of the position of the non-null entries, so that its computation time is O(

The only way I was thinking about to do this is to get the weight matrix, and to do it by hand, reconstructing a new network from the input calculated in an external program that the keras API.

Hi @anon3811548 you can use tf.sparse.from_dense method which will return only elements not equal to zero. For reference please refer to this documentation. Thanks!

Ok, sorry for the late answer, but this exactly what I was searching for.
Thanks a lot !