Skip to content

Commit 538ed1a

Browse files
committed
Fixed annotation metadata copy
1 parent 8cca865 commit 538ed1a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

backend/database/annotations.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
class AnnotationModel(DynamicDocument):
1313

14-
COCO_PROPERTIES = ["id", "image_id", "category_id", "segmentation", \
15-
"iscrowd", "color", "area", "bbox", "metadata", \
14+
COCO_PROPERTIES = ["id", "image_id", "category_id", "segmentation",
15+
"iscrowd", "color", "area", "bbox", "metadata",
1616
"keypoints"]
1717

1818
id = SequenceField(primary_key=True)
@@ -30,7 +30,7 @@ class AnnotationModel(DynamicDocument):
3030
height = IntField()
3131

3232
color = StringField()
33-
33+
3434
keypoints = ListField(default=[])
3535

3636
metadata = DictField(default={})
@@ -42,9 +42,8 @@ class AnnotationModel(DynamicDocument):
4242
milliseconds = IntField(default=0)
4343
events = EmbeddedDocumentListField(Event)
4444

45-
4645
def __init__(self, image_id=None, **data):
47-
46+
4847
from .images import ImageModel
4948

5049
if image_id is not None:
@@ -60,7 +59,7 @@ def __init__(self, image_id=None, **data):
6059

6160
def save(self, copy=False, *args, **kwargs):
6261

63-
if not self.dataset_id and not copy:
62+
if self.dataset_id and not copy:
6463
dataset = DatasetModel.objects(id=self.dataset_id).first()
6564

6665
if dataset is not None:
@@ -113,7 +112,7 @@ def __call__(self):
113112
}
114113

115114
return im.Annotation(**data)
116-
115+
117116
def add_event(self, e):
118117
self.update(push__events=e)
119118

backend/webserver/api/annotations.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
api = Namespace('annotation', description='Annotation related operations')
1212

1313
create_annotation = reqparse.RequestParser()
14-
create_annotation.add_argument('image_id', type=int, required=True, location='json')
14+
create_annotation.add_argument(
15+
'image_id', type=int, required=True, location='json')
1516
create_annotation.add_argument('category_id', type=int, location='json')
1617
create_annotation.add_argument('metadata', type=dict, location='json')
1718
create_annotation.add_argument('segmentation', type=list, location='json')
@@ -41,8 +42,9 @@ def post(self):
4142
image = current_user.images.filter(id=image_id, deleted=False).first()
4243
if image is None:
4344
return {"message": "Invalid image id"}, 400
44-
45-
logger.info(f'{current_user.username} has created an annotation for image {image_id}')
45+
46+
logger.info(
47+
f'{current_user.username} has created an annotation for image {image_id}')
4648

4749
try:
4850
annotation = AnnotationModel(
@@ -69,7 +71,7 @@ def get(self, annotation_id):
6971

7072
if annotation is None:
7173
return {"message": "Invalid annotation id"}, 400
72-
74+
7375
return query_util.fix_ids(annotation)
7476

7577
@login_required
@@ -80,10 +82,12 @@ def delete(self, annotation_id):
8082
if annotation is None:
8183
return {"message": "Invalid annotation id"}, 400
8284

83-
image = current_user.images.filter(id=annotation.image_id, deleted=False).first()
85+
image = current_user.images.filter(
86+
id=annotation.image_id, deleted=False).first()
8487
image.flag_thumbnail()
8588

86-
annotation.update(set__deleted=True, set__deleted_date=datetime.datetime.now())
89+
annotation.update(set__deleted=True,
90+
set__deleted_date=datetime.datetime.now())
8791
return {'success': True}
8892

8993

@@ -92,5 +96,3 @@ def delete(self, annotation_id):
9296
# def get(self, annotation_id):
9397
# """ Returns the binary mask of an annotation """
9498
# return query_util.fix_ids(AnnotationModel.objects(id=annotation_id).first())
95-
96-

0 commit comments

Comments
 (0)