From c3855055c275909a1e53b7a040ff8c821540b9fc Mon Sep 17 00:00:00 2001
From: Nikolai <osterei33@gmx.de>
Date: Wed, 15 Aug 2018 16:22:02 +0200
Subject: [PATCH] (hopefully) correct treatment of class_weight

---
 toolkit.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/toolkit.py b/toolkit.py
index 598d60e..3ea7528 100755
--- a/toolkit.py
+++ b/toolkit.py
@@ -811,8 +811,9 @@ class ClassificationProject(object):
                                self.y_train.reshape(-1, 1),
                                epochs=epochs,
                                validation_split = self.validation_split,
-                               class_weight=self.class_weight,
-                               sample_weight=self.w_train,
+                               # we have to multiply by class weight since keras ignores class weight if sample weight is given
+                               # see https://github.com/keras-team/keras/issues/497
+                               sample_weight=self.w_train*np.array(self.class_weight)[self.y_train.astype(int)],
                                shuffle=True,
                                batch_size=self.batch_size,
                                callbacks=self.callbacks_list)
-- 
GitLab