Load a tensorflow (saved) model and set_weights on one layer, where shape of new weights != shape of old weights

87 views
Skip to first unread message

wamba naomie

unread,
Aug 4, 2021, 5:46:41 PM8/4/21
to Keras-users

I want to use a pre-trained saved model to continue training on a new dataset with different inputs. So I changed the shape of the kernel weights of the LSTM model (since the kernel weights depend on the input size) so that it fits to the input of the new data.

But when I apply model.layers[2].set_weights([new_weights]) (where new weights includes kernel, recurrent and bias weights), I get the following error:

ValueError: Layer weight shape (2, 5) not compatible with provided weight shape (3, 5)

I guess this is because, the weights used in .set_weights() should be of the same shape like those in .get_weights() but I was wandering if there was a way to change the input dimension of the weights?

Thanks

Lance Norskog

unread,
Aug 4, 2021, 8:50:09 PM8/4/21
to wamba naomie, Keras-users
I do not think that this is possible.

What you can do is add one or more Dense layers that learn how to translate your data samples into an embedding for the LSTM input.

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/21491c0c-e9b3-4de9-a2da-ee922b102f5dn%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA
Reply all
Reply to author
Forward
0 new messages