Skip to content

Conversation

@giswqs
Copy link
Member

@giswqs giswqs commented Dec 23, 2025

Fix opengeos/geoai#447.

Allows setting environment SAM3_CHECKPOINT_PATH to use local SAM 3 for QGIS Plugin

Copilot AI review requested due to automatic review settings December 23, 2025 16:59
Copy link
Contributor

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 adds support for using a local SAM3 checkpoint file by introducing a new environment variable SAM3_CHECKPOINT_PATH. When set, this environment variable allows users (particularly QGIS Plugin users) to specify a local checkpoint path instead of downloading from HuggingFace, addressing issue #447.

  • Added environment variable handling to read SAM3_CHECKPOINT_PATH and override the checkpoint path
  • Added validation to ensure the specified checkpoint path exists before use
  • Set load_from_HF to False when using local checkpoints

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +203 to +204
if os.environ.get("SAM3_CHECKPOINT_PATH") is not None:
checkpoint_path = os.environ.get("SAM3_CHECKPOINT_PATH")
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The environment variable is retrieved twice using os.environ.get("SAM3_CHECKPOINT_PATH"). Store the result in a variable on line 203 to avoid the redundant call on line 204.

Suggested change
if os.environ.get("SAM3_CHECKPOINT_PATH") is not None:
checkpoint_path = os.environ.get("SAM3_CHECKPOINT_PATH")
env_checkpoint_path = os.environ.get("SAM3_CHECKPOINT_PATH")
if env_checkpoint_path is not None:
checkpoint_path = env_checkpoint_path

Copilot uses AI. Check for mistakes.
Comment on lines +203 to +205
if os.environ.get("SAM3_CHECKPOINT_PATH") is not None:
checkpoint_path = os.environ.get("SAM3_CHECKPOINT_PATH")
load_from_HF = False
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

Consider stripping whitespace from the environment variable value to handle cases where SAM3_CHECKPOINT_PATH might have leading or trailing whitespace. This would prevent unexpected errors when users accidentally include whitespace in their environment variable definition.

Suggested change
if os.environ.get("SAM3_CHECKPOINT_PATH") is not None:
checkpoint_path = os.environ.get("SAM3_CHECKPOINT_PATH")
load_from_HF = False
env_checkpoint = os.environ.get("SAM3_CHECKPOINT_PATH")
if env_checkpoint is not None:
env_checkpoint = env_checkpoint.strip()
if env_checkpoint:
checkpoint_path = env_checkpoint
load_from_HF = False

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

@github-actions github-actions bot temporarily deployed to pull request December 23, 2025 17:03 Inactive
@giswqs giswqs merged commit 482c381 into main Dec 23, 2025
16 checks passed
@giswqs giswqs deleted the checkpoint branch December 23, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to set the local sam3

2 participants