AttributeError tf-nightly class weight

Viewed 442

I am working with tf-nightly version.

In the previous version, class weights as the array input works.

But, the nightly version is throwing the error.

weights = np.array([3.4,  10.11,  10.67,  11.52,  0.23,  0.001,  19.86])

model.fit(data, labels, epochs=10,class_weight = weights)

Error Message:

class_ids = list(sorted(class_weight.keys()))
AttributeError: 'list' object has no attribute 'keys'

weights in the dictionary form,

weights = {0: 3.4,  1: 10.11,  2: 10.67,  3: 11.52,  4: 0.23,  5: 0.001,  6: 19.86}
1 Answers

I don't think there is a change in the class_weight parameter it has always been a dictionary object.

class_weight    Optional dictionary mapping class indices (integers) 

This is definition is from the stable version and not from the nightly. I went back to check the API documentation from tensorflow2.0rc and even in that documentation, it is a dictionary and not an array.

So to answer short, it is not a change in Nightly, but it since rc2.0 in TensorFlow.

In which version were you able to use your above code without issues? and Did you want to try sample_weight instead? sample_weight does take an array of weights.

I hope my answer helps you.

Related