Skip to content
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

Fix/luxonis dataset converter #90

Merged
merged 4 commits into from
Mar 3, 2025
Merged
Changes from 3 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
61 changes: 33 additions & 28 deletions datadreamer/utils/luxonis_dataset_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,44 +122,44 @@ def dataset_generator():
h = min(box[3] / height - y, 1 - y)
annotation["boundingbox"] = {"x": x, "y": y, "w": w, "h": h}

if has_masks:
mask = image_data["masks"][i]
if isinstance(mask, list):
poly = [(point[0] / width, point[1] / height) for point in mask]
annotation["instance_segmentation"] = {
"points": poly,
"height": height,
"width": width,
}
else:
annotation["instance_segmentation"] = {
"counts": mask["counts"],
"height": mask["size"][0],
"width": mask["size"][1],
}

yield {
"file": image_full_path,
"task": f"datadreamer_{task}",
"annotation": annotation,
}
if has_masks:
mask = image_data["masks"][i]
if isinstance(mask, list):
poly = [
(point[0] / width, point[1] / height) for point in mask
]
annotation["instance_segmentation"] = {
"points": poly,
"height": height,
"width": width,
}
else:
annotation["instance_segmentation"] = {
"counts": mask["counts"],
"height": mask["size"][0],
"width": mask["size"][1],
}

yield {
"file": image_full_path,
"task": f"datadreamer_{task}",
"annotation": annotation,
}

dataset_name = (
os.path.basename(output_dir)
if self.dataset_name is None or self.dataset_name == ""
else self.dataset_name
)

if LuxonisDataset.exists(dataset_name):
dataset = LuxonisDataset(dataset_name)
dataset.delete_dataset()

# if dataset_plugin is set, use that
if self.dataset_plugin:
if "GOOGLE_APPLICATION_CREDENTIALS" in os.environ:
logger.info(f"Using {self.dataset_plugin} dataset")
dataset_constructor = DATASETS_REGISTRY.get(self.dataset_plugin)
dataset = dataset_constructor(dataset_name)
dataset = dataset_constructor(
dataset_name, delete_existing=True, delete_remote=True
Copy link
Member

Choose a reason for hiding this comment

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

delete_existing and delete_remote are not typically present in datasets from the registry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But even if it is not typical, isn't better to still have it there, so maybe in the future it might be needed?

Copy link
Member

Choose a reason for hiding this comment

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

Ok, we can keep it.

)
else:
raise ValueError(
"GOOGLE_APPLICATION_CREDENTIALS environment variable is not set for using the dataset plugin."
Expand All @@ -170,10 +170,15 @@ def dataset_generator():
and "GOOGLE_APPLICATION_CREDENTIALS" in os.environ
):
logger.info("Using GCS bucket")
dataset = LuxonisDataset(dataset_name, bucket_storage=BucketStorage.GCS)
dataset = LuxonisDataset(
dataset_name,
bucket_storage=BucketStorage.GCS,
delete_existing=True,
delete_remote=True,
)
else:
logger.info("Using local dataset")
dataset = LuxonisDataset(dataset_name)
dataset = LuxonisDataset(dataset_name, delete_existing=True)

dataset.add(dataset_generator())

Expand Down
Loading