Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/kitti_export_object_detection/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = "KITTI object detection export plugin for Lightly Studio"
requires-python = ">=3.9"
dependencies = [
"lightly_studio>=1.0.0",
"lightly_studio>=1.0.4",
"labelformat",
"sqlmodel",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sqlmodel import Session

from lightly_studio.core.image.image_sample import ImageSample
from lightly_studio.export.image_dataset_export import image_sample_to_image
from lightly_studio.export.lightly_studio_label_input import (
LightlyStudioObjectDetectionInput,
)
Expand Down Expand Up @@ -51,7 +52,13 @@ def __init__(
images_root: Common root path used to preserve nested image folders.
"""
self._images_root = images_root
super().__init__(session=session, dataset_id=dataset_id, samples=samples)
super().__init__(
session=session,
dataset_id=dataset_id,
samples=samples,
annotation_collection_id=None,
Comment thread
mrpositron marked this conversation as resolved.
sample_to_image=image_sample_to_image,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

def get_images(self) -> list[Image]:
"""Return images with filenames relative to the KITTI output folder."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from sqlmodel import Session
from ultralytics import YOLO # type: ignore[attr-defined]
from ultralytics.engine.results import Results

from lightly_studio.models.annotation.annotation_base import (
AnnotationCreate,
Expand Down Expand Up @@ -140,8 +141,8 @@ def execute(
total_annotations_created = 0
for i, image_entry in enumerate(samples, start=1):
try:
results = model(
image_entry.file_path_abs, conf=confidence, verbose=False
result = list(
model(image_entry.file_path_abs, conf=confidence, verbose=False)
)[0]
except Exception as e:
logger.error(
Expand All @@ -153,12 +154,22 @@ def execute(
success=False,
message=f"Failed to run inference on '{image_entry.file_path_abs}': {e}",
)
for box in results.boxes:
category_id = int(box.cls)
# A single image always yields one `Results`; `embed=` is never passed.
assert isinstance(result, Results)
boxes = result.boxes
if boxes is None:
logger.warning(
"No boxes returned for '%s'; is '%s' a detection model?",
image_entry.file_path_abs,
model_path,
)
continue
for box_index in range(len(boxes)):
Comment thread
mrpositron marked this conversation as resolved.
category_id = int(boxes.cls[box_index])
label_id = label_map.get(category_id)
if label_id is None:
continue
x_center, y_center, w, h = box.xywh[0].tolist()
x_center, y_center, w, h = boxes.xywh[box_index].tolist()
Comment thread
mrpositron marked this conversation as resolved.
annotations_to_create.append(
AnnotationCreate(
annotation_label_id=label_id,
Expand All @@ -168,7 +179,7 @@ def execute(
y=round(y_center - h / 2),
width=max(1, round(w)),
height=max(1, round(h)),
confidence=float(box.conf),
confidence=float(boxes.conf[box_index]),
)
)

Expand Down
Loading