From 2d18805c287fb606baeb58101723ed0e3d233f65 Mon Sep 17 00:00:00 2001 From: Jihye Jeong Date: Wed, 4 Feb 2026 19:11:33 +0100 Subject: [PATCH 1/2] feat: add Hugging Face support to ClassifierContainer (#19) --- mapreader/classify/classifier.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mapreader/classify/classifier.py b/mapreader/classify/classifier.py index 671d41bd..3aece18b 100644 --- a/mapreader/classify/classifier.py +++ b/mapreader/classify/classifier.py @@ -108,6 +108,7 @@ def __init__( is_inception: bool = False, load_path: str | None = None, force_device: bool = False, + huggingface=False, **kwargs, ): # set up device @@ -141,6 +142,7 @@ def __init__( ) self.labels_map = labels_map + self.huggingface = huggingface # set up model and move to device print("[INFO] Initializing model.") @@ -149,7 +151,25 @@ def __init__( self.input_size = input_size self.is_inception = is_inception elif isinstance(model, str): - self._initialize_model(model, **kwargs) + if self.huggingface: + try: + from transformers import AutoModelForImageClassification, AutoImageProcessor + except ImportError: + raise ImportError( + "Hugging Face models require the 'transformers' library: 'pip install transformers'." + ) + print(f"[INFO] Initializing Hugging Face model: {model}") + num_labels = len(self.labels.map) + self.model = AutoModelForImageClassification.from_pretrained( + model, + num_labels=num_labels, + ignore_mismatched_sizes=True + ).to(self.device) + self.hf_processor = AutoImageProcessor.from_pretrained(model) + self.input_size = getattr(self.hf_processor, "size", {"height": 224})["height"] + self.is_inception = False + else: + self._initialize_model(model, **kwargs) self.optimizer = None self.scheduler = None From 8cf2c25e16d313e2ee88e202ac7ba0f531d88b4b Mon Sep 17 00:00:00 2001 From: Jihye Jeong Date: Wed, 4 Feb 2026 19:32:25 +0100 Subject: [PATCH 2/2] feat: fix typo and support Hugging Face models (#192/hut101-#19) --- mapreader/classify/classifier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapreader/classify/classifier.py b/mapreader/classify/classifier.py index 3aece18b..fe4acbc4 100644 --- a/mapreader/classify/classifier.py +++ b/mapreader/classify/classifier.py @@ -159,7 +159,7 @@ def __init__( "Hugging Face models require the 'transformers' library: 'pip install transformers'." ) print(f"[INFO] Initializing Hugging Face model: {model}") - num_labels = len(self.labels.map) + num_labels = len(self.labels_map) self.model = AutoModelForImageClassification.from_pretrained( model, num_labels=num_labels,