Skip to content

Feature/sam2 features#3

Open
folkien wants to merge 22 commits intomainfrom
feature/sam2_features
Open

Feature/sam2 features#3
folkien wants to merge 22 commits intomainfrom
feature/sam2_features

Conversation

@folkien
Copy link
Copy Markdown
Contributor

@folkien folkien commented Jul 12, 2025

No description provided.

Copilot AI review requested due to automatic review settings July 12, 2025 20:09
@folkien folkien self-assigned this Jul 12, 2025
Copy link
Copy Markdown

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 integrates SAM2-based segmentation to compute and cache embeddings, and adds an interactive PyQt5 GUI for browsing images, viewing detections and masks, and filtering by embedding similarity.

  • Introduces Sam2Runner to run SAM2 on image crops and pool features into embeddings.
  • Updates DatasetManager and FeatureIndex to build or load a persistent embedding index.
  • Implements a PyQt5 GUI (MainWindow and ImageViewer) for image/detection lists and similarity-based filtering.

Reviewed Changes

Copilot reviewed 13 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ssya/widgets/image_viewer.py Added widget to render images with bounding boxes, masks, and similarity scores.
ssya/models/detection.py Defined Detection dataclass and bounding-box normalization conversion.
ssya/main.py Built main PyQt5 GUI logic: file/detection lists, sliders, and filter actions.
ssya/helpers/metrics.py Added cosine_similarity utility.
ssya/controllers/sam2_wrapper.py Wrapped SAM2 inference to produce masks and embeddings.
ssya/controllers/features_index.py Created FeatureIndex for embedding persistence and lookup.
ssya/controllers/dataset_manager.py Manages dataset loading, annotation parsing, index building/loading.
pyproject.toml Declared sam2 dependency.
README.md Updated project overview, installation, usage, and documentation (in Polish).
.vscode/launch.json Updated VSCode debug configuration for the new entrypoint.
Comments suppressed due to low confidence (1)

.vscode/launch.json:18

  • Remove the stray comma on its own line to fix invalid JSON syntax in the launch configuration.
            ,

for det in detections:
if det.embedding is None:
for e in self.entries:
if e["image_idx"] == det.image_idx and e["det_idx"] == det.class_id:
Copy link

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

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

This condition compares the stored det_idx against det.class_id, but det_idx represents the detection's position, not its class. Consider comparing e['det_idx'] to the detection's index or storing class_id instead to ensure correct embedding lookup.

Copilot uses AI. Check for mistakes.
self.detections[img_path] = [
Detection(int(cls), (float(xc), float(yc), float(w), float(h)), img_idx) for cls, xc, yc, w, h in lines
]
logger.info("Dataset: %d images (%d with annotations)", len(self.images), len(self.detections))
Copy link

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

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

len(self.detections) returns the total number of images (keys in the dict), not only those with annotations. To accurately log images with annotations, count entries where the detection list is non-empty.

Suggested change
logger.info("Dataset: %d images (%d with annotations)", len(self.images), len(self.detections))
logger.info("Dataset: %d images (%d with annotations)", len(self.images), sum(1 for dets in self.detections.values() if dets))

Copilot uses AI. Check for mistakes.
self.lbl = QLabel(alignment=Qt.AlignCenter)
self.lbl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.lbl.setScaledContents(True)
# Fixed with and height set, 1920 - 200 , 1080 - 200
Copy link

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

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

Typo in comment: 'with' should be 'width'.

Suggested change
# Fixed with and height set, 1920 - 200 , 1080 - 200
# Fixed width and height set, 1920 - 200 , 1080 - 200

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +32
# Fixed with and height set, 1920 - 200 , 1080 - 200
self.lbl.setFixedWidth(1620)
self.lbl.setFixedHeight(880)
Copy link

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

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

[nitpick] Using hardcoded width and height may limit flexibility; consider making these dimensions configurable or adapting to the parent layout dynamically.

Suggested change
# Fixed with and height set, 1920 - 200 , 1080 - 200
self.lbl.setFixedWidth(1620)
self.lbl.setFixedHeight(880)
# Allow dynamic resizing based on parent layout
self.lbl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.lbl.setScaledContents(True)

Copilot uses AI. Check for mistakes.
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.

2 participants