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

Incremental save of annotation. #120

Merged
merged 13 commits into from
Oct 15, 2018
Prev Previous commit
Next Next commit
fixed comments
  • Loading branch information
Andrey Zhavoronkov committed Oct 10, 2018
commit 7c2cdaaa8520b8b4314664a760be620f98374f10
35 changes: 14 additions & 21 deletions cvat/apps/engine/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,29 +1498,22 @@ def to_client(self):
def validate_data_from_client(self, data):
# check unique id for each object
client_ids = set()
def extract_and_check_clinet_id(obj):
if 'client_id' not in box:
raise Exception('No client_id field in received data')
client_id = obj['client_id']
if obj['client_id'] in client_ids:
def extract_and_check_clinet_id(shape):
if 'client_id' not in shape:
raise Exception('No client_id field in received data')
client_id = shape['client_id']
if client_id in client_ids:
raise Exception('More than one object has the same client_id {}'.format(client_id))
client_ids.add(client_id)
return client_id

for action in ['create', 'update', 'delete']:
for box in data[action]['boxes']:
extract_and_check_clinet_id(box)

for poly_shape_type in ['points', 'polygons', 'polylines']:
for poly_shape in data[action][poly_shape_type]:
extract_and_check_clinet_id(box)
shape_types = ['boxes', 'points', 'polygons', 'polylines', 'box_paths',
'points_paths', 'polygon_paths', 'polyline_paths']

for path in data[action]['box_paths']:
extract_and_check_clinet_id(path)

for poly_path_type in ['points_paths', 'polygon_paths', 'polyline_paths']:
for path in data[action][poly_path_type]:
extract_and_check_clinet_id(path)
for action in ['create', 'update', 'delete']:
for shape_type in shape_types:
for shape in data[action][shape_type]:
extract_and_check_clinet_id(shape)

class _AnnotationForSegment(_Annotation):
def __init__(self, db_segment):
Expand Down Expand Up @@ -2066,7 +2059,7 @@ def _flip_shape(shape, im_w, im_h):
("xbr", "{:.2f}".format(shape.xbr)),
("ybr", "{:.2f}".format(shape.ybr)),
("occluded", str(int(shape.occluded))),
("client_id", "{}".format(shape.client_id)),
("client_id", str(shape.client_id)),
])
if db_task.z_order:
dump_dict['z_order'] = str(shape.z_order)
Expand All @@ -2086,7 +2079,7 @@ def _flip_shape(shape, im_w, im_h):
)) for p in shape.points.split(' '))
)),
("occluded", str(int(shape.occluded))),
("client_id", "{}".format(shape.client_id)),
("client_id", str(shape.client_id)),
])

if db_task.z_order:
Expand Down Expand Up @@ -2134,7 +2127,7 @@ def _flip_shape(shape, im_w, im_h):
dump_dict = OrderedDict([
("id", str(path_idx)),
("label", path.label.name),
("client_id", "{}".format(path.client_id)),
("client_id", str(path.client_id)),
])
if path.group_id:
dump_dict['group_id'] = str(path.group_id)
Expand Down