python_for_microscopists icon indicating copy to clipboard operation
python_for_microscopists copied to clipboard

Unable to use class_weights: `class_weight` not supported for 3+ dimensional targets.

Open iamkashish opened this issue 3 years ago • 0 comments

I have 9 classes and one is for background. But when I pass class_weight to model.fit(), an error pops in: class_weight not supported for 3+ dimensional targets.

I'm using the following set of lines to calculate class_weights

classweights = class_weight.compute_class_weight('balanced', classes = np.unique(y), y= y_reshaped) 
class_weights = {}
for i in range(n_classes):
   class_weights[i] = classweights[i]
print(class_weights)

iamkashish avatar Jun 09 '22 13:06 iamkashish