8000 Initialize ai model when needed in canvas by wkentaro · Pull Request #1596 · wkentaro/labelme · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Initialize ai model when needed in canvas #1596

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

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

wkentaro
Copy link
Owner
@wkentaro wkentaro commented Jun 3, 2025

Why?

  • We don't need to check self._sam anymore
  • createMode switch doesn't need to initialize ai model.

@wkentaro wkentaro requested a review from Copilot June 3, 2025 22:13
@wkentaro wkentaro self-assigned this Jun 3, 2025
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors AI model initialization in the canvas to defer loading until needed by storing just the model name and retrieving the model via a cached helper function.

  • Removed direct model instance storage (self._sam) and initialization calls.
  • Introduced set_ai_model_name to update the selected model name.
  • Added _get_ai_model with lru_cache for on-demand model instantiation.
  • Updated UI event handlers in app.py to use the new model naming API.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
labelme/widgets/canvas.py Replaced eager model init with storing model name and _get_ai_model helper; removed initializeAiModel.
labelme/app.py Updated combo-box signals to call set_ai_model_name; removed old init connectors and reordered index setting.
Comments suppressed due to low confidence (3)

labelme/widgets/canvas.py:135

  • [nitpick] Method names in this class use camelCase; consider renaming set_ai_model_name to setAiModelName for consistency.
def set_ai_model_name(self, model_name: str) -> None:

labelme/widgets/canvas.py:1035

  • This helper is public to the module but lacks a docstring. Add a brief description of its purpose, parameters, and return behavior.
def _get_ai_model(model_name: str) -> osam.types.Model:

labelme/widgets/canvas.py:135

  • The new set_ai_model_name method and caching logic lack unit tests. Consider adding tests to verify that the model name is updated correctly and that _get_ai_model returns and caches the right model instance.
def set_ai_model_name(self, model_name: str) -> None:

@wkentaro wkentaro merged commit a41b32c into main Jun 3, 2025
3 checks passed
@wkentaro wkentaro deleted the initialize_ai_model_when_needed_in_canvas branch June 3, 2025 22:15
@Tanya-Verma
Copy link

Grt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0