Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does get_weights return an empty list?

I am teaching myself data science and something peculiar has caught my eyes. In a sample DNN tutorial I was working on, I found that the Keras layer.get_weights() function returned empty list for my variables. I've successfully cross validated and used model.fit() function to compute the recall scores.

But as I'm trying to use the get_weights() function on my categorical variables, it returns empty weights for all.

I'm not looking for a solution to code but I am just curious about what would possibly cause this. I've read through the Keras API but it did not provide me with the information I was hoping to see. What could cause the get_weights() function in Keras to return empty list except for of course the weights not being set?

like image 580
Ishiro Kusabi Avatar asked Nov 04 '17 02:11

Ishiro Kusabi


1 Answers

Maybe you are asking for weights before they are created.

Weights are created when the Model is first called on inputs or build() is called with an input_shape.

For example, if you load weights from checkpoint but you don't give an input_shape to the model, then get_weights() will return an empty list.

like image 151
pbon Avatar answered Sep 28 '22 01:09

pbon