@@ -335,23 +335,14 @@ def open_model(self, target: law.LocalDirectoryTarget) -> dict[str, Any]:
335
335
models ["parameters" ] = yaml .load (f_in , Loader = yaml .Loader )
336
336
337
337
# custom loss needed due to output layer changes for negative weights
338
- from hbw .ml .tf_util import cumulated_crossentropy , categorical_crossentropy
338
+ from hbw .ml .tf_util import cumulated_crossentropy
339
339
340
- # Check for negative weight handling and assign loss function accordingly.
341
- if self .negative_weights == "ignore" :
342
- models ["model" ] = tf .keras .models .load_model (
343
- target ["mlmodel" ].path , custom_objects = {categorical_crossentropy .__name__ : categorical_crossentropy },
344
- )
345
- models ["best_model" ] = tf .keras .models .load_model (
346
- target ["checkpoint" ].path , custom_objects = {categorical_crossentropy .__name__ : categorical_crossentropy },
347
- )
348
- else :
349
- models ["model" ] = tf .keras .models .load_model (
350
- target ["mlmodel" ].path , custom_objects = {cumulated_crossentropy .__name__ : cumulated_crossentropy },
351
- )
352
- models ["best_model" ] = tf .keras .models .load_model (
353
- target ["checkpoint" ].path , custom_objects = {cumulated_crossentropy .__name__ : cumulated_crossentropy },
354
- )
340
+ models ["model" ] = tf .keras .models .load_model (
341
+ target ["mlmodel" ].path , custom_objects = {cumulated_crossentropy .__name__ : cumulated_crossentropy },
342
+ )
343
+ models ["best_model" ] = tf .keras .models .load_model (
344
+ target ["checkpoint" ].path , custom_objects = {cumulated_crossentropy .__name__ : cumulated_crossentropy },
345
+ )
355
346
356
347
return models
357
348
@@ -553,7 +544,7 @@ def prepare_ml_model(
553
544
554
545
from keras .models import Sequential
555
546
from keras .layers import Dense , BatchNormalization
556
- from hbw .ml .tf_util import cumulated_crossentropy , categorical_crossentropy
547
+ from hbw .ml .tf_util import cumulated_crossentropy
557
548
558
549
n_inputs = len (set (self .input_features ))
559
550
n_outputs = len (self .processes )
@@ -576,7 +567,7 @@ def prepare_ml_model(
576
567
optimizer = keras .optimizers .Adam (learning_rate = 0.00050 )
577
568
if self .negative_weights == "ignore" :
578
569
model .compile (
579
- loss = categorical_crossentropy ,
570
+ loss = " categorical_crossentropy" ,
580
571
optimizer = optimizer ,
581
572
weighted_metrics = ["categorical_accuracy" ],
582
573
)
0 commit comments