Skip to content

Commit a080beb

Browse files
Narek MkhitaryanNarek Mkhitaryan
authored andcommitted
removed _objects, _pixel postfixes in download_image_annotations and import_annotations logic
1 parent 24fb61c commit a080beb

File tree

17 files changed

+52
-115
lines changed

17 files changed

+52
-115
lines changed

src/superannotate/lib/app/input_converters/converters/coco_converters/coco_to_sa_pixel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def coco_panoptic_segmentation_to_sa_pixel(coco_path, output_dir):
9090
cv2.imwrite(str(output_dir / ("%s___save.png" % annot["file_name"])), img)
9191

9292
images_converted.append(annot["file_name"])
93-
file_name = "%s___pixel.json" % annot["file_name"]
93+
file_name = f"{annot['file_name']}.json"
9494
sa_metadata = {
9595
"name": annot_name,
9696
"width": img_id_to_shape[str(annot["image_id"])]["width"],
@@ -138,7 +138,7 @@ def coco_instance_segmentation_to_sa_pixel(coco_path, output_dir):
138138
logger.info("Converting to SuperAnnotate JSON format")
139139
tqdm_thread.start()
140140
for id_, annotations in images_dict.items():
141-
file_name = "%s___pixel.json" % annotations["file_name"]
141+
file_name = f"{annotations['file_name']}.json"
142142
hexcolors = blue_color_generator(len(annotations["annotations"]))
143143
mask = np.zeros(annotations["shape"])
144144
H, W, _ = mask.shape

src/superannotate/lib/app/input_converters/converters/coco_converters/coco_to_sa_vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def save_sa_jsons(coco_json, img_id_to_annot, output_dir):
5757
sa_instances = []
5858
else:
5959
sa_instances = img_id_to_annot[str(img["id"])]
60-
file_name = "%s___objects.json" % image_path
60+
file_name = f"{image_path}.json"
6161

6262
sa_metadata = {
6363
"name": image_path,

src/superannotate/lib/app/input_converters/converters/dataloop_converters/dataloop_to_sa_vector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ def dataloop_to_sa(input_dir, task, output_dir):
105105
sa_tags.append(ann["label"])
106106

107107
if "name" in sa_metadata:
108-
file_name = "%s___objects.json" % sa_metadata["name"]
108+
file_name = f"{sa_metadata['name']}.json"
109109
else:
110-
file_name = "%s___objects.json" % dl_data["filename"][1:]
110+
file_name = f"{dl_data['filename'][1:]}.json"
111111

112-
images_converted.append(file_name.replace("___objects.json ", ""))
112+
images_converted.append(file_name.replace(".json", ""))
113113
json_template = _create_sa_json(sa_instances, sa_metadata, sa_tags, sa_comments)
114114
write_to_json(output_dir / file_name, json_template)
115115
finish_event.set()

src/superannotate/lib/app/input_converters/converters/googlecloud_converters/googlecloud_to_sa_vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def googlecloud_to_sa_vector(path, output_dir):
4545
images_not_converted.append(file_name)
4646
continue
4747

48-
sa_file_name = "%s___objects.json" % Path(file_name).name
48+
sa_file_name = f"{Path(file_name).name}.json"
4949

5050
points = (row[3] * W, row[4] * H, row[5] * W, row[8] * H)
5151
sa_instances = _create_vector_instance("bbox", points, {}, [], row[2])

src/superannotate/lib/app/input_converters/converters/labelbox_converters/labelbox_to_sa_pixel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def labelbox_instance_segmentation_to_sa_pixel(json_data, output_dir, input_dir)
3535
logger.info("Converting to SuperAnnotate JSON format")
3636
tqdm_thread.start()
3737
for data in json_data:
38-
file_name = data["External ID"] + "___pixel.json"
38+
file_name = data["External ID"] + ".json"
3939
mask_name = data["External ID"] + "___save.png"
4040
sa_metadata = {"name": data["External ID"]}
4141
if "objects" not in data["Label"].keys():

src/superannotate/lib/app/input_converters/converters/labelbox_converters/labelbox_to_sa_vector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def labelbox_to_sa(json_data, output_dir, task):
3737
tqdm_thread.start()
3838
for data in json_data:
3939
if "objects" not in data["Label"].keys():
40-
file_name = data["External ID"] + "___objects.json"
40+
file_name = data["External ID"] + ".json"
4141
write_to_json(
4242
output_dir / file_name,
4343
{"metadata": {}, "instances": [], "tags": [], "comments": []},
@@ -87,7 +87,7 @@ def labelbox_to_sa(json_data, output_dir, task):
8787
sa_instances.append(sa_obj)
8888

8989
images_converted.append(data["External ID"])
90-
file_name = "%s___objects.json" % data["External ID"]
90+
file_name = f"{data['External ID']}.json"
9191
try:
9292
img = cv2.imread(str(output_dir / data["External ID"]))
9393
H, W, _ = img.shape

src/superannotate/lib/app/input_converters/converters/sagemaker_converters/sagemaker_to_sa_pixel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def sagemaker_instance_segmentation_to_sa_pixel(data_path, output_dir):
9191

9292
blue_colors = blue_color_generator(num_of_contours)
9393
idx = 0
94-
file_name = "%s___pixel.json" % (img_mapping[mask_name])
94+
file_name = f"{img_mapping[mask_name]}.json"
9595
sa_metadata = {"name": img_mapping[mask_name], "width": W, "height": H}
9696
sa_instances = []
9797
sa_mask = np.zeros((H, W, 4))

src/superannotate/lib/app/input_converters/converters/sagemaker_converters/sagemaker_to_sa_vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def sagemaker_object_detection_to_sa_vector(data_path, main_key, output_dir):
4444
raise Exception
4545

4646
manifest = dataset_manifest[int(img["datasetObjectId"])]
47-
file_name = "%s___objects.json" % Path(manifest["source-ref"]).name
47+
file_name = f"{Path(manifest['source-ref']).name}.json"
4848

4949
classes = img["consolidatedAnnotation"]["content"][main_key + "-metadata"][
5050
"class-map"

src/superannotate/lib/app/input_converters/converters/supervisely_converters/supervisely_to_sa_pixel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def supervisely_instance_segmentation_to_sa_pixel(json_files, class_id_map, outp
3434
tqdm_thread.start()
3535

3636
for json_file in json_files:
37-
file_name = "%s___pixel.json" % Path(json_file).stem
37+
file_name = f"{Path(json_file).stem}.json"
3838

3939
json_data = json.load(open(json_file))
4040
sa_instances = []
@@ -78,7 +78,7 @@ def supervisely_instance_segmentation_to_sa_pixel(json_files, class_id_map, outp
7878
cv2.imwrite(
7979
str(
8080
output_dir
81-
/ file_name.replace("___pixel.json", "___save.png")
81+
/ file_name.replace(".json", "___save.png")
8282
),
8383
mask,
8484
)

src/superannotate/lib/app/input_converters/converters/supervisely_converters/supervisely_to_sa_vector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def supervisely_to_sa(json_files, class_id_map, task, output_dir):
3636
tqdm_thread.start()
3737
for json_file in json_files:
3838
json_data = json.load(open(json_file))
39-
file_name = "%s___objects.json" % Path(json_file).stem
39+
file_name = f"{Path(json_file).stem}.json"
4040
sa_metadata = {
4141
"name": Path(json_file).stem,
4242
"width": json_data["size"]["width"],
@@ -140,7 +140,7 @@ def supervisely_keypoint_detection_to_sa_vector(
140140
logger.info("Converting to SuperAnnotate JSON format")
141141
tqdm_thread.start()
142142
for json_file in json_files:
143-
file_name = "%s___objects.json" % (Path(json_file).stem)
143+
file_name = f"{Path(json_file).stem}.json"
144144
json_data = json.load(open(json_file))
145145
sa_metadata = {
146146
"name": Path(json_file).stem,

0 commit comments

Comments
 (0)