-
Notifications
You must be signed in to change notification settings - Fork 22
Hut101 19 jhwisdom #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Hut101 19 jhwisdom #577
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would skip setting |
||||||||||||||||||
|
|
||||||||||||||||||
| # 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) | ||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could also be just |
||||||||||||||||||
| self.input_size = getattr(self.hf_processor, "size", {"height": 224})["height"] | ||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking here there seem to be 3 options for how size is defined. Could you implement these, i.e.:
Suggested change
|
||||||||||||||||||
| self.is_inception = False | ||||||||||||||||||
| else: | ||||||||||||||||||
| self._initialize_model(model, **kwargs) | ||||||||||||||||||
|
|
||||||||||||||||||
| self.optimizer = None | ||||||||||||||||||
| self.scheduler = None | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a type hint here