Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2517312
Code cleanup
hovnatan Apr 2, 2021
32fba21
Update logging for attach images
Apr 2, 2021
664641e
Add limitations
dshabin Apr 5, 2021
75221a8
Merge develop
dshabin Apr 5, 2021
26910a9
Merge pull request #18 from superannotateai/folder-limitations
davitavagyan Apr 5, 2021
3eaa8f5
Update version.py
dshabin Apr 5, 2021
3a3d644
Fix training
dshabin Apr 6, 2021
69cb0eb
Merge branch 'develop' of https://github.com/superannotateai/superann…
dshabin Apr 6, 2021
8215cbb
Merge pull request #19 from superannotateai/folder-limitations
dshabin Apr 6, 2021
8f24510
Update version.py
dshabin Apr 6, 2021
82f3fa2
Video upload cleanup
dshabin Apr 8, 2021
0ff8921
Merge pull request #20 from superannotateai/folder-limitations
dshabin Apr 8, 2021
7fc7034
Update version.py
dshabin Apr 8, 2021
fdf0c2b
Fix video frames count
dshabin Apr 8, 2021
e464097
public links name column dtype fix
ero1311 Apr 9, 2021
8427214
Fix copy_images - video
dshabin Apr 9, 2021
df493d0
Merge commit
dshabin Apr 9, 2021
8e2de64
Merge pull request #21 from superannotateai/folder-limitations
dshabin Apr 9, 2021
b2bbf1b
Update version.py
dshabin Apr 9, 2021
3863ac2
Fix copy images
dshabin Apr 12, 2021
414b3c9
Merge pull request #22 from superannotateai/folder-limitations
dshabin Apr 12, 2021
f79e894
Update version.py
dshabin Apr 12, 2021
9972f13
Fixed hanging issue
Apr 13, 2021
c31e04c
Update version.py
davitavagyan Apr 13, 2021
43f140b
Move function fix, test fix
Apr 13, 2021
15eaa30
Update version.py
davitavagyan Apr 13, 2021
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
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ disable=
no-else-return,
too-many-lines,
too-many-arguments,
too-many-instance-attributes
too-many-instance-attributes,
broad-except

[SPELLING]

Expand Down
2 changes: 1 addition & 1 deletion superannotate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def consensus(*args, **kwargs):
download_image_preannotations, get_image_annotations, get_image_bytes,
get_image_metadata, get_image_preannotations, search_images,
search_images_all_folders, set_image_annotation_status,
set_images_annotation_statuses, upload_image_annotations
set_images_annotation_statuses, upload_image_annotations, get_project_root_folder_id
)
from .db.project_api import (
create_folder, delete_folders, get_folder_metadata,
Expand Down
8 changes: 8 additions & 0 deletions superannotate/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
"Failed": 4
}

_MODEL_TRAINING_TASKS = {
"Instance Segmentation for Pixel Projects" : "instance_segmentation_pixel",
"Instance Segmentation for Vector Projects" : "instance_segmentation_vector",
"Keypoint Detection for Vector Projects" : "keypoint_detection_vector",
"Object Detection for Vector Projects" : "object_detection_vector",
"Semantic Segmentation for Pixel Projects" : "semantic_segmentation_pixel"
}


def prediction_segmentation_status_from_str_to_int(status):
return _PREDICTION_SEGMENTATION_STATUSES[status]
Expand Down
34 changes: 18 additions & 16 deletions superannotate/db/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,32 @@ def get_image_metadata(project, image_names, return_dict_on_single_output=True):
else:
project_folder_id = None

chunk_size = 500
chunks = [image_names[i:i + chunk_size] for i in range(0, len(image_names), chunk_size)]

json_req = {
'project_id': project['id'],
'team_id': _api.team_id,
'names': image_names,
}

if project_folder_id is not None:
json_req["folder_id"] = project_folder_id
response = _api.send_request(
req_type='POST',
path='/images/getBulk',
json_req=json_req,
)
if not response.ok:
raise SABaseException(
response.status_code,
"Couldn't get image metadata. " + response.text
)

metadata_raw = response.json()
metadata_raw = []
for chunk in chunks:
json_req['names'] = chunk
response = _api.send_request(
req_type='POST',
path='/images/getBulk',
json_req=json_req,
)
if not response.ok:
raise SABaseException(response.status_code,"Couldn't get image metadata. " + response.text)
metadata_raw += response.json()

metadata_without_deleted = []
for im_metadata in metadata_raw:
if 'delete' in im_metadata and im_metadata['delete'] == 1:
continue
metadata_without_deleted.append(im_metadata)
metadata_without_deleted = [ i for i in metadata_raw if i['delete'] != 1 ]

if len(metadata_without_deleted) == 0:
raise SABaseException(
0,
Expand Down
75 changes: 40 additions & 35 deletions superannotate/db/project_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
from .project_api import get_project_and_folder_metadata
from .projects import (
__create_image, get_image_array_to_upload,
get_project_default_image_quality_in_editor, upload_image_array_to_s3
get_project_default_image_quality_in_editor, upload_image_array_to_s3,
_get_available_image_counts
)
from .utils import _get_upload_auth_token

logger = logging.getLogger("superannotate-python-sdk")
_api = API.get_instance()
Expand Down Expand Up @@ -50,7 +52,8 @@ def upload_image_to_project(
Can be either "compressed" or "original". If None then the default value in project settings will be used.
:type image_quality_in_editor: str
"""
project, project_folder = get_project_and_folder_metadata(project)
initial_project_inp = project
project, folder = get_project_and_folder_metadata(project)
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
if upload_state == "External":
raise SABaseException(
Expand Down Expand Up @@ -92,20 +95,14 @@ def upload_image_to_project(
0, "Image name img_name should be set if img is not Pathlike"
)

if folder:
folder_id = folder["id"]
else:
folder_id = get_project_root_folder_id(project)

team_id, project_id = project["team_id"], project["id"]
params = {
'team_id': team_id,
}
response = _api.send_request(
req_type='GET',
path=f'/project/{project_id}/sdkImageUploadToken',
params=params
)
if not response.ok:
raise SABaseException(
response.status_code, "Couldn't get upload token " + response.text
)
res = response.json()
params = {'team_id': team_id, 'folder_id': folder_id}
res = _get_upload_auth_token(params=params, project_id=project_id)
prefix = res['filePath']
s3_session = boto3.Session(
aws_access_key_id=res['accessKeyId'],
Expand All @@ -120,24 +117,20 @@ def upload_image_to_project(
)
key = upload_image_array_to_s3(bucket, *images_info_and_array, prefix)
except Exception as e:
raise SABaseException(0, "Couldn't upload to data server. " + str(e))
raise SABaseException(0, "Couldn't upload to data server.") from e

if project_folder is not None:
project_folder_id = project_folder["id"]
else:
project_folder_id = None
__create_image(
[img_name], [key],
project,
annotation_status,
prefix, [images_info_and_array[2]],
project_folder_id,
folder_id,
upload_state="Basic"
)

while True:
try:
get_image_metadata(project, img_name)
get_image_metadata(initial_project_inp, img_name)
except SABaseException:
time.sleep(0.2)
else:
Expand Down Expand Up @@ -171,7 +164,8 @@ def _copy_images(
destination_folder_id = get_project_root_folder_id(destination_project)
json_req["destination_folder_id"] = destination_folder_id
res = {}
res['skipped'] = 0
res['skipped'] = []
res['completed'] = []
for start_index in range(0, len(image_names), NUM_TO_SEND):
json_req["image_names"] = image_names[start_index:start_index +
NUM_TO_SEND]
Expand All @@ -187,6 +181,7 @@ def _copy_images(
response.status_code, "Couldn't copy images " + response.text
)
res['skipped'] += response.json()['skipped']
res['completed'] += response.json()['completed']

for image_name in image_names:
_copy_annotations_and_metadata(
Expand Down Expand Up @@ -219,6 +214,8 @@ def copy_images(
:type copy_annotation_status: bool
:param copy_pin: enables image pin status copy
:type copy_pin: bool
:return: list of skipped image names
:rtype: list of strs
"""
source_project, source_project_folder = get_project_and_folder_metadata(
source_project
Expand All @@ -228,20 +225,30 @@ def copy_images(
)
if image_names is None:
image_names = search_images((source_project, source_project_folder))

limit = _get_available_image_counts(
destination_project, destination_project_folder
)
imgs_to_upload = image_names[:limit]
res = _copy_images(
(source_project, source_project_folder),
(destination_project, destination_project_folder), image_names,
(destination_project, destination_project_folder), imgs_to_upload,
include_annotations, copy_annotation_status, copy_pin
)
uploaded_imgs = res['completed']
skipped_imgs = [i for i in imgs_to_upload if i not in uploaded_imgs]

skipped_images_count = len(skipped_imgs) + len(image_names[limit:])

logger.info(
"Copied images %s from %s to %s. Number of skipped images %s",
image_names,
source_project["name"] + "" if source_project_folder is None else "/" +
source_project_folder["name"], destination_project["name"] +
"" if destination_project_folder is None else "/" +
destination_project_folder["name"], res["skipped"]
uploaded_imgs, source_project["name"] +
"" if source_project_folder is None else source_project["name"] + "/" +
source_project_folder["name"], destination_project["name"] + ""
if destination_project_folder is None else destination_project["name"] +
"/" + destination_project_folder["name"], skipped_images_count
)
return res["skipped"]
return skipped_imgs


def delete_images(project, image_names):
Expand Down Expand Up @@ -322,11 +329,9 @@ def move_images(
)
if image_names is None:
image_names = search_images((source_project, source_project_folder))
_copy_images(
(source_project, source_project_folder),
(destination_project, destination_project_folder), image_names,
include_annotations, copy_annotation_status, copy_pin
)
copy_images((source_project, source_project_folder), image_names,
(destination_project, destination_project_folder),
include_annotations, copy_annotation_status, copy_pin)
delete_images((source_project, source_project_folder), image_names)
logger.info(
"Moved images %s from project %s to project %s", image_names,
Expand Down
Loading