bnsreenu / python_for_microscopists

https://www.youtube.com/channel/UC34rW-HtPJulxr5wp2Xa04w?sub_confirmation=1
MIT License
3.91k stars 2.39k forks source link

when using git code 208 while using class weights getting issue #14

Open sumanttyagi opened 3 years ago

sumanttyagi commented 3 years ago

please help : when using below history = model.fit(train_x, train_y, batch_size = 16, verbose=1, epochs=10, validation_data=(test_x,test_y), class_weight=class_weights, shuffle= True)

-> 1185 if class_weight: 1186 dataset = dataset.map(_make_class_weight_map_fn(class_weight)) 1187 self._inferred_steps = self._infer_steps(steps_per_epoch, dataset)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

iamkashish commented 2 years ago

Hey @sumanttyagi You can try the following 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)