为什么get_weights返回一个空列表? [英] Why does get_weights return an empty list?

查看:304
本文介绍了为什么get_weights返回一个空列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自学数据科学,一些奇特的东西引起了我的注意.在我正在研究的示例DNN教程中,我发现Keras layer.get_weights()函数返回了变量的空列表.我已经成功地交叉验证并使用model.fit()函数来计算召回得分.

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.

但是当我尝试在分类变量上使用get_weights()函数时,它会为所有变量返回空权重.

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

我不是在寻找代码解决方案,但我只是想知道可能会导致这种情况的原因.我已经阅读了Keras API,但没有为我提供我希望看到的信息.是什么会导致Keras中的get_weights()函数返回空列表,除了当然没有设置权重?

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?

推荐答案

也许您是在创建权重之前要求它们.

Maybe you are asking for weights before they are created.

首次在输入上调用模型或创建模型时创建权重 build()input_shape调用.

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

例如,如果您从检查点加载权重,但没有给模型提供input_shape,则get_weights()将返回一个空列表.

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.

这篇关于为什么get_weights返回一个空列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆