Easiest way to get/set flattened array of trainable weights (and biases)

For example i want to be able to do something like this…

weights = model.get_trainable_weights() weights *= 2 model.set_trainable_weights(weights) 

I’ve googled it and seems like getting trainable weights might be pretty straightforward, but i’m not finding anything on being able to supply a flat array of weights for the model to set.

Right now I’m manually tracking the shapes, calculating which part of the flat array is for this tensor then taking that subset and reshaping it. It’s seems more difficult than it needs to be plus its also pretty expensive computationally taking as long as a tenth of a second just to set weights.

submitted by /u/Yogi_DMT
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *