Skip to content

Commit

Permalink
skip or transform option, logs
Browse files Browse the repository at this point in the history
  • Loading branch information
almazgimaev committed Oct 23, 2023
1 parent 2f4728e commit dc3dda3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/convert_sly_to_yolov5.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
TEAM_ID = int(os.environ["context.teamId"])
WORKSPACE_ID = int(os.environ["context.workspaceId"])
PROJECT_ID = int(os.environ["modal.state.slyProjectId"])
PROCCESS_SHAPES = os.environ.get("modal.state.processShapes", "transform")
PROCCESS_SHAPES_MSG = "skipped" if PROCCESS_SHAPES == "skip" else "transformed to rectangles"

TRAIN_TAG_NAME = "train"
VAL_TAG_NAME = "val"
Expand Down Expand Up @@ -78,19 +80,16 @@ def transform(api: sly.Api, task_id, context, state, app_logger):
)

error_classes = []
ok_classes = []
for obj_class in meta.obj_classes:
if obj_class.geometry_type != sly.Rectangle:
error_classes.append(obj_class)
else:
ok_classes.append(obj_class)
if len(error_classes) > 0:
sly.logger.warn(
f"Project has unsupported classes. All unsupported classes will be transformed to rectangles: "
f"Project has unsupported classes. "
f"Objects with unsupported geometry types will be {PROCCESS_SHAPES_MSG}"
f"{[obj_class.name for obj_class in error_classes]}"
)


def _write_new_ann(path, content):
with open(path, "a") as f1:
f1.write("\n".join(content))
Expand All @@ -109,6 +108,7 @@ def _add_to_split(image_id, img_name, split_ids, split_image_paths, labels_dir,
for dataset in api.dataset.get_list(PROJECT_ID):
images = api.image.get_list(dataset.id)

unsupported_shapes = 0
train_ids = []
train_image_paths = []
val_ids = []
Expand All @@ -125,6 +125,10 @@ def _add_to_split(image_id, img_name, split_ids, split_image_paths, labels_dir,

yolov5_ann = []
for label in ann.labels:
if label.obj_class.geometry_type != sly.Rectangle:
unsupported_shapes += 1
if PROCCESS_SHAPES == "skip":
continue
yolov5_ann.append(transform_label(class_names, ann.img_size, label))

image_processed = False
Expand Down Expand Up @@ -167,6 +171,11 @@ def _add_to_split(image_id, img_name, split_ids, split_image_paths, labels_dir,
api.image.download_paths(dataset.id, val_ids, val_image_paths)

progress.iters_done_report(len(batch))
if unsupported_shapes > 0:
app_logger.warn(
f"Dataset {dataset.name} has {unsupported_shapes} objects with unsupported geometry types. "
f"These objects will be {PROCCESS_SHAPES_MSG}"
)

data_yaml = {
"train": "../{}/images/train".format(result_dir_name),
Expand Down

0 comments on commit dc3dda3

Please sign in to comment.