警告:tensorflow:sample_weight模式从...强制为['...'] [英] WARNING:tensorflow:sample_weight modes were coerced from ... to ['...']

查看:536
本文介绍了警告:tensorflow:sample_weight模式从...强制为['...']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用.fit_generator().fit()训练图像分类器,并将字典作为参数传递给class_weight=.

Training an image classifier using .fit_generator() or .fit() and passing a dictionary to class_weight= as an argument.

我从未在TF1.x中出现错误,但是在2.1中,开始训练时得到以下输出:

I never got errors in TF1.x but in 2.1 I get the following output when starting training:

WARNING:tensorflow:sample_weight modes were coerced from
  ...
    to  
  ['...']

强制从...['...']的东西是什么意思?

What does it mean to coerce something from ... to ['...']?

tensorflow的回购上此警告的来源为此处,放置的评论为:

The source for this warning on tensorflow's repo is here, comments placed are:

试图将sample_weight_modes强制转换为目标结构.这隐含地依赖于模型展平其内部表示形式的输出的事实.

Attempt to coerce sample_weight_modes to the target structure. This implicitly depends on the fact that Model flattens outputs for its internal representation.

推荐答案

这似乎是虚假消息.升级到TensorFlow 2.1后,我得到了相同的警告消息,但是我根本不使用任何类权重或样本权重.我确实使用了返回如下元组的生成器:

This seems like a bogus message. I get the same warning message after upgrading to TensorFlow 2.1, but I do not use any class weights or sample weights at all. I do use a generator that returns a tuple like this:

return inputs, targets

现在我将其更改为以下内容,以消除警告:

And now I just changed it to the following to make the warning go away:

return inputs, targets, [None]

我不知道这是否相关,但是我的模型使用3个输入,因此我的inputs变量实际上是3个numpy数组的列表. targets只是单个numpy数组.

I don't know if this is relevant, but my model uses 3 inputs, so my inputs variable is actually a list of 3 numpy arrays. targets is just a single numpy array.

无论如何,这只是一个警告.无论哪种方式,培训都可以正常进行.

In any case, it's just a warning. The training works fine either way.

此错误似乎已在TensorFlow 2.2中修复,这很棒.但是,上面的修复将在TF 2.2中失败,因为它会尝试获取样本权重的形状,显然,AttributeError: 'NoneType' object has no attribute 'shape'将失败.因此,在升级到2.2时,请撤消上述修复程序.

This bug seems to have been fixed in TensorFlow 2.2, which is great. However the fix above will fail in TF 2.2, because it will try to get the shape of the sample weights, which will obviously fail with AttributeError: 'NoneType' object has no attribute 'shape'. So undo the above fix when upgrading to 2.2.

这篇关于警告:tensorflow:sample_weight模式从...强制为['...']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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