From 691a021e7b7e2f66f1aeab4bd5679759c3e1ea01 Mon Sep 17 00:00:00 2001 From: Mathis Frahm Date: Fri, 18 Aug 2023 11:29:47 +0200 Subject: [PATCH] change default producer order and minor cleanup --- hbw/config/defaults_and_groups.py | 3 ++- hbw/production/categories.py | 18 +++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/hbw/config/defaults_and_groups.py b/hbw/config/defaults_and_groups.py index 547815ca..3f719abe 100644 --- a/hbw/config/defaults_and_groups.py +++ b/hbw/config/defaults_and_groups.py @@ -69,7 +69,8 @@ def default_producers(cls, container, task_params): # if a ML model is set, and the task is neither MLTraining nor MLEvaluation, # use the ml categorization producer if ml_model not in (None, law.NO_STR, RESOLVE_DEFAULT, tuple()) and not is_ml_task: - default_producers.insert(0, f"ml_{ml_model}") + # NOTE: this producer needs to be added as the last element! otherwise, category_ids will be overwritten + default_producers.append(f"ml_{ml_model}") # if we're running the inference_model, we don't need the ml_inputs # NOTE: we cannot skip ml_inputs, because it is needed for cf.MLEvaluation diff --git a/hbw/production/categories.py b/hbw/production/categories.py index bd149c7a..31567f7d 100644 --- a/hbw/production/categories.py +++ b/hbw/production/categories.py @@ -35,10 +35,8 @@ def pre_ml_cats(self: Producer, events: ak.Array, **kwargs) -> ak.Array: @pre_ml_cats.init def pre_ml_cats_init(self: Producer) -> None: - if self.config_inst.x("add_categories_production", True): - # add categories but only on first call - add_categories_production(self.config_inst) - self.config_inst.x.add_categories_production = False + # add categories to config inst + add_categories_production(self.config_inst) @producer( @@ -76,15 +74,9 @@ def ml_cats_init(self: Producer) -> None: if not self.ml_model_name: self.ml_model_name = "dense_default" - if self.config_inst.x("add_categories_production", True): - # add categories but only on first call - add_categories_production(self.config_inst) - self.config_inst.x.add_categories_production = False - - if self.config_inst.x("add_categories_ml", True): - # add ml categories but only on first call - add_categories_ml(self.config_inst, dense_test) - self.config_inst.x.add_categories_ml = False + # add categories to config inst + add_categories_production(self.config_inst) + add_categories_ml(self.config_inst, dense_test) # get all the derived DenseClassifier models and instantiate a corresponding producer