I would like to know if the class weighting is also used in evaluating the loss in the validation data during the training. If not, is there a way to adjust the fit() function so that it takes into account the class weighting during the validation loss calculation.

  • $\begingroup$ I wonder why you want to add weights to the class during validation!! $\endgroup$
    – enterML
    Sep 7, 2017 at 5:52

1 Answer 1


As described in the tensorflow docs[1], validation_data can be a tuple (inputs, targets, sample_weights). So, you can use this parameter for class weighting during the validation loss calculation.

[1] https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit

  • 1
    $\begingroup$ This is sample weight, which means that I have to check for each class sample and make a vector that has the right class weight for each sample $\endgroup$
    – HatemB
    Sep 4, 2017 at 12:49
  • 1
    $\begingroup$ @moh Any idea how to supply class weight for validation data when using a generator? $\endgroup$
    – Eran
    Sep 26, 2018 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.