Skip to content

Commit 135c8c1

Browse files
committed
upload_image_annotations rename
1 parent 40678b5 commit 135c8c1

File tree

10 files changed

+45
-66
lines changed

10 files changed

+45
-66
lines changed

.pylintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[BASIC]
2+
good-names=df,f,e
3+
14
[MASTER]
25
load-plugins=pylint_pytest
36

docs/source/superannotate.sdk.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ ______
7777
.. autofunction:: superannotate.get_image_preannotations
7878
.. autofunction:: superannotate.download_image_annotations
7979
.. autofunction:: superannotate.download_image_preannotations
80-
.. autofunction:: superannotate.upload_annotations_from_json_to_image
80+
.. autofunction:: superannotate.upload_image_annotations
8181
.. autofunction:: superannotate.copy_image
8282
.. autofunction:: superannotate.move_image
8383
.. autofunction:: superannotate.pin_image

docs/source/tutorial.sdk.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ and upload back to the platform with:
367367

368368
.. code-block:: python
369369
370-
sa.upload_annotations_from_json_to_image(project, image, "<path_to_json>")
370+
sa.upload_image_annotations(project, image, "<path_to_json>")
371371
372372
Last two steps can be combined into one:
373373

superannotate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
create_fuse_image, delete_image, download_image, download_image_annotations,
4646
download_image_preannotations, get_image_annotations, get_image_bytes,
4747
get_image_metadata, get_image_preannotations, search_images,
48-
set_image_annotation_status, upload_annotations_from_json_to_image
48+
set_image_annotation_status, upload_image_annotations
4949
)
5050
from .db.project_images import (
5151
assign_images, copy_image, move_image, pin_image, upload_image_to_project

superannotate/db/images.py

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
)
1818
from ..api import API
1919
from ..common import (
20-
annotation_status_str_to_int, deprecated_alias, hex_to_rgb,
21-
image_path_to_annotation_paths, project_type_int_to_str
20+
annotation_status_str_to_int, hex_to_rgb, image_path_to_annotation_paths,
21+
project_type_int_to_str
2222
)
2323
from ..exceptions import SABaseException
2424
from .annotation_classes import (
@@ -201,9 +201,7 @@ def add_annotation_comment_to_image(
201201
comment_author,
202202
resolved=resolved
203203
)
204-
upload_annotations_from_json_to_image(
205-
project, image_name, annotations, verbose=False
206-
)
204+
upload_image_annotations(project, image_name, annotations, verbose=False)
207205

208206

209207
def add_annotation_bbox_to_image(
@@ -239,9 +237,7 @@ def add_annotation_bbox_to_image(
239237
annotation_class_attributes,
240238
error,
241239
)
242-
upload_annotations_from_json_to_image(
243-
project, image_name, annotations, verbose=False
244-
)
240+
upload_image_annotations(project, image_name, annotations, verbose=False)
245241

246242

247243
def add_annotation_polygon_to_image(
@@ -275,9 +271,7 @@ def add_annotation_polygon_to_image(
275271
annotations, polygon, annotation_class_name,
276272
annotation_class_attributes, error
277273
)
278-
upload_annotations_from_json_to_image(
279-
project, image_name, annotations, verbose=False
280-
)
274+
upload_image_annotations(project, image_name, annotations, verbose=False)
281275

282276

283277
def add_annotation_polyline_to_image(
@@ -310,9 +304,7 @@ def add_annotation_polyline_to_image(
310304
annotations, polyline, annotation_class_name,
311305
annotation_class_attributes, error
312306
)
313-
upload_annotations_from_json_to_image(
314-
project, image_name, annotations, verbose=False
315-
)
307+
upload_image_annotations(project, image_name, annotations, verbose=False)
316308

317309

318310
def add_annotation_point_to_image(
@@ -345,9 +337,7 @@ def add_annotation_point_to_image(
345337
annotations, point, annotation_class_name, annotation_class_attributes,
346338
error
347339
)
348-
upload_annotations_from_json_to_image(
349-
project, image_name, annotations, verbose=False
350-
)
340+
upload_image_annotations(project, image_name, annotations, verbose=False)
351341

352342

353343
def add_annotation_ellipse_to_image(
@@ -380,9 +370,7 @@ def add_annotation_ellipse_to_image(
380370
annotations, ellipse, annotation_class_name,
381371
annotation_class_attributes, error
382372
)
383-
upload_annotations_from_json_to_image(
384-
project, image_name, annotations, verbose=False
385-
)
373+
upload_image_annotations(project, image_name, annotations, verbose=False)
386374

387375

388376
def add_annotation_template_to_image(
@@ -422,9 +410,7 @@ def add_annotation_template_to_image(
422410
annotations, template_points, template_connections,
423411
annotation_class_name, annotation_class_attributes, error
424412
)
425-
upload_annotations_from_json_to_image(
426-
project, image_name, annotations, verbose=False
427-
)
413+
upload_image_annotations(project, image_name, annotations, verbose=False)
428414

429415

430416
def add_annotation_cuboid_to_image(
@@ -460,9 +446,7 @@ def add_annotation_cuboid_to_image(
460446
annotations, cuboid, annotation_class_name, annotation_class_attributes,
461447
error
462448
)
463-
upload_annotations_from_json_to_image(
464-
project, image_name, annotations, verbose=False
465-
)
449+
upload_image_annotations(project, image_name, annotations, verbose=False)
466450

467451

468452
def download_image(
@@ -628,9 +612,7 @@ def get_image_preannotations(project, image_name):
628612
raise SABaseException(response.status_code, response.text)
629613
res = response.json()
630614

631-
annotation_classes = search_annotation_classes(
632-
project
633-
)
615+
annotation_classes = search_annotation_classes(project)
634616
annotation_classes_dict = get_annotation_classes_id_to_name(
635617
annotation_classes
636618
)
@@ -724,9 +706,7 @@ def get_image_annotations(project, image_name, project_type=None):
724706
raise SABaseException(response.status_code, response.text)
725707
res = response.json()
726708

727-
annotation_classes = search_annotation_classes(
728-
project
729-
)
709+
annotation_classes = search_annotation_classes(project)
730710
annotation_classes_dict = get_annotation_classes_id_to_name(
731711
annotation_classes
732712
)
@@ -853,8 +833,7 @@ def download_image_preannotations(project, image_name, local_dir_path):
853833
return tuple(return_filepaths)
854834

855835

856-
@deprecated_alias(mask_path="mask")
857-
def upload_annotations_from_json_to_image(
836+
def upload_image_annotations(
858837
project, image_name, annotation_json, mask=None, verbose=True
859838
):
860839
"""Upload annotations from JSON (also mask for pixel annotations)
@@ -886,9 +865,7 @@ def upload_annotations_from_json_to_image(
886865
"Uploading annotations for image %s in project %s.", image_name,
887866
project["name"]
888867
)
889-
annotation_classes = search_annotation_classes(
890-
project
891-
)
868+
annotation_classes = search_annotation_classes(project)
892869
annotation_classes_dict = get_annotation_classes_name_to_id(
893870
annotation_classes
894871
)

superannotate/db/project_images.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
from .images import (
1313
delete_image, get_image_annotations, get_image_bytes, get_image_metadata,
1414
search_images, set_image_annotation_status,
15-
upload_annotations_from_json_to_image
15+
upload_image_annotations
1616
)
17+
from .project_api import get_project_metadata_bare
1718
from .projects import (
1819
__create_image, _get_project_image_quality_in_editor,
19-
get_image_array_to_upload
20+
get_image_array_to_upload, upload_image_array_to_s3
2021
)
21-
from .project_api import get_project_metadata_bare
2222

2323
logger = logging.getLogger("superannotate-python-sdk")
2424
_api = API.get_instance()
@@ -100,15 +100,10 @@ def upload_image_to_project(
100100
)
101101
s3_resource = s3_session.resource('s3')
102102
bucket = s3_resource.Bucket(res["bucket"])
103-
orig_image, lores_image, huge_image, thumbnail_image = get_image_array_to_upload(
104-
img, image_quality_in_editor
105-
)
103+
images = get_image_array_to_upload(img, image_quality_in_editor)
106104
key = prefix + f'{img_name}'
107105
try:
108-
bucket.put_object(Body=orig_image, Key=key)
109-
bucket.put_object(Body=lores_image, Key=key + '___lores.jpg')
110-
bucket.put_object(Body=huge_image, Key=key + '___huge.jpg')
111-
bucket.put_object(Body=thumbnail_image, Key=key + '___thumb.jpg')
106+
upload_image_array_to_s3(bucket, *images, key)
112107
except Exception as e:
113108
raise SABaseException(0, "Couldn't upload to data server. " + e)
114109

@@ -180,13 +175,13 @@ def copy_image(
180175
annotations = get_image_annotations(source_project, image_name)
181176
if annotations["annotation_json"] is not None:
182177
if "annotation_mask" in annotations:
183-
upload_annotations_from_json_to_image(
178+
upload_image_annotations(
184179
destination_project, new_name,
185180
annotations["annotation_json"],
186181
annotations["annotation_mask"]
187182
)
188183
else:
189-
upload_annotations_from_json_to_image(
184+
upload_image_annotations(
190185
destination_project, new_name,
191186
annotations["annotation_json"]
192187
)

superannotate/db/projects.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import cgi
12
import copy
23
import io
34
import json
@@ -8,17 +9,16 @@
89
import tempfile
910
import threading
1011
import time
11-
from pathlib import Path
12-
import requests
13-
import cgi
1412
from os.path import basename
13+
from pathlib import Path
1514
from urllib.parse import urlparse
1615

1716
import boto3
1817
import cv2
1918
import ffmpeg
20-
from google.cloud import storage
19+
import requests
2120
from azure.storage.blob import BlobServiceClient
21+
from google.cloud import storage
2222
from PIL import Image, ImageOps
2323
from tqdm import tqdm
2424

@@ -539,6 +539,15 @@ def upload_images_from_folder_to_project(
539539
)
540540

541541

542+
def upload_image_array_to_s3(
543+
bucket, orig_image, lores_image, huge_image, thumbnail_image, key
544+
):
545+
bucket.put_object(Body=orig_image, Key=key)
546+
bucket.put_object(Body=lores_image, Key=key + '___lores.jpg')
547+
bucket.put_object(Body=huge_image, Key=key + '___huge.jpg')
548+
bucket.put_object(Body=thumbnail_image, Key=key + '___thumb.jpg')
549+
550+
542551
def get_image_array_to_upload(byte_io_orig, image_quality_in_editor):
543552
Image.MAX_IMAGE_PIXELS = None
544553
im = Image.open(byte_io_orig)
@@ -638,13 +647,8 @@ def __upload_images_to_aws_thread(
638647
couldnt_upload[thread_id].append(path)
639648
continue
640649
try:
641-
orig_image, lores_image, huge_image, thumbnail_image = get_image_array_to_upload(
642-
file, image_quality_in_editor
643-
)
644-
bucket.put_object(Body=orig_image, Key=key)
645-
bucket.put_object(Body=lores_image, Key=key + '___lores.jpg')
646-
bucket.put_object(Body=huge_image, Key=key + '___huge.jpg')
647-
bucket.put_object(Body=thumbnail_image, Key=key + '___thumb.jpg')
650+
images = get_image_array_to_upload(file, image_quality_in_editor)
651+
upload_image_array_to_s3(bucket, *images, key)
648652
except Exception as e:
649653
logger.warning("Unable to upload to data server %s.", e)
650654
couldnt_upload[thread_id].append(path)

tests/test_basic_images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_basic_images(project_type, name, description, from_folder, tmpdir):
5151

5252
assert (Path(tmpdir) / image_name).is_file()
5353

54-
sa.upload_annotations_from_json_to_image(
54+
sa.upload_image_annotations(
5555
project, image_name,
5656
sa.image_path_to_annotation_paths(
5757
from_folder / image_name, project_type

tests/test_fuse_gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_fuse_image_create_pixel(tmpdir):
102102
sa.create_annotation_classes_from_classes_json(
103103
project, "./tests/sample_project_pixel/classes/classes.json"
104104
)
105-
sa.upload_annotations_from_json_to_image(
105+
sa.upload_image_annotations(
106106
PROJECT_NAME_PIXEL, "example_image_1.jpg",
107107
"./tests/sample_project_pixel/example_image_1.jpg___pixel.json",
108108
"./tests/sample_project_pixel/example_image_1.jpg___save.png"

tests/test_image_copy_move.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_image_copy_mult(tmpdir):
2828
sa.create_annotation_classes_from_classes_json(
2929
project, "./tests/sample_project_vector/classes/classes.json"
3030
)
31-
sa.upload_annotations_from_json_to_image(
31+
sa.upload_image_annotations(
3232
project, "example_image_1.jpg",
3333
"./tests/sample_project_vector/example_image_1.jpg___objects.json"
3434
)

0 commit comments

Comments
 (0)