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

前端 未结 4 1153
遥遥无期
遥遥无期 2021-02-01 00:29

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

I never go

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 01:05

    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]
    

    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.

    Edit for TensorFlow 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.

提交回复
热议问题