custom constraint of weight matrix
By far the easiest way to ensure that is to check wether the trained W has determinant 0. If it doesn't then you're OK to go, if it does you can add a small constant (1e-7) to any weight in the matrix and solve the issue. I can tell you anyway that the odds of zero determinant happenning are almost negligible.
I want to invert a classifier on MNIST dataset on keras, thus the determinant of weight matrix must not be zero. Then I can use x=W-1f-1(y) 
But there is no custom constraint in keras.