-
Notifications
You must be signed in to change notification settings - Fork 11
Add general detector + global moth model to example pipeline #992
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
Open
mihow
wants to merge
4
commits into
main
Choose a base branch
from
feat/global-moths-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9f8b826
feat: add a real moth classifier to processing service
mihow cf00c3e
feat: add global moth classifier to example pipeline
mihow 9bd828b
fix: prefer black formatter's whitespace style
mihow fcfcd87
Merge branch 'main' into feat/global-moths-model
mihow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Cache directories for models and dependencies | ||
| cache/ | ||
| huggingface_cache/ | ||
| pytorch_cache/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,237 @@ | ||||||
| """ | ||||||
| Simplified base classes for inference models without database dependencies. | ||||||
| Adapted from trapdata.ml.models.base but streamlined for processing service use. | ||||||
| """ | ||||||
|
|
||||||
| import json | ||||||
| import logging | ||||||
| from typing import Any | ||||||
|
|
||||||
| import torch | ||||||
| import torchvision.transforms | ||||||
|
|
||||||
| from .utils import get_best_device, get_or_download_file | ||||||
|
|
||||||
| logger = logging.getLogger(__name__) | ||||||
|
|
||||||
|
|
||||||
| # Standard normalization transforms | ||||||
| imagenet_normalization = torchvision.transforms.Normalize( | ||||||
| mean=[0.485, 0.456, 0.406], # RGB | ||||||
| std=[0.229, 0.224, 0.225], # RGB | ||||||
| ) | ||||||
|
|
||||||
| tensorflow_normalization = torchvision.transforms.Normalize( | ||||||
| mean=[0.5, 0.5, 0.5], # RGB | ||||||
| std=[0.5, 0.5, 0.5], # RGB | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| class SimplifiedInferenceBase: | ||||||
| """ | ||||||
| Simplified base class for inference models without database or queue dependencies. | ||||||
| """ | ||||||
|
|
||||||
| name: str = "Unknown Inference Model" | ||||||
| description: str = "" | ||||||
| weights_path: str | None = None | ||||||
| labels_path: str | None = None | ||||||
| category_map: dict[int, str] = {} | ||||||
| num_classes: int | None = None | ||||||
| default_taxon_rank: str = "SPECIES" | ||||||
| normalization = tensorflow_normalization | ||||||
| batch_size: int = 4 | ||||||
| device: str | None = None | ||||||
|
|
||||||
| def __init__(self, **kwargs): | ||||||
| # Override any class attributes with provided kwargs | ||||||
| for k, v in kwargs.items(): | ||||||
| setattr(self, k, v) | ||||||
|
|
||||||
| logger.info(f"Initializing simplified inference class {self.name}") | ||||||
|
|
||||||
| self.device = self.device or get_best_device() | ||||||
| self.category_map = self.get_labels(self.labels_path) | ||||||
| self.num_classes = self.num_classes or len(self.category_map) | ||||||
| self.weights = self.get_weights(self.weights_path) | ||||||
| self.transforms = self.get_transforms() | ||||||
|
|
||||||
| logger.info(f"Loading model for {self.name} with {len(self.category_map or [])} categories") | ||||||
| self.model = self.get_model() | ||||||
|
||||||
| self.model = self.get_model() | |
| self.model = None # Model should be initialized in subclass after all setup |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This call to SimplifiedInferenceBase.get_transforms in an initialization method is overridden by ResNet50Base.get_transforms.
This call to SimplifiedInferenceBase.get_transforms in an initialization method is overridden by GlobalMothClassifier.get_transforms.