Skip to content

Commit

Permalink
Integration of REST/API in client (Part 9) (#377)
Browse files Browse the repository at this point in the history
* Fixed: version of undefined
* Fixed overlap
* Fixed parser
  • Loading branch information
bsekachev authored and nmanovic committed Apr 4, 2019
1 parent 6beb278 commit 7ce6eb6
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 143 deletions.
6 changes: 3 additions & 3 deletions cvat/apps/dashboard/static/dashboard/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class TaskView {

if (next) {
const response = await $.ajax({
url: `/api/v1/tasks/${this._id}/annotations`,
url: `/api/v1/tasks/${this._id}/annotations?action=create`,
type: 'PATCH',
data: JSON.stringify(chunk),
contentType: 'application/json',
Expand All @@ -114,12 +114,12 @@ class TaskView {
}

async function save(parsed) {3
const response = await $.ajax({
await $.ajax({
url: `/api/v1/tasks/${this._id}/annotations`,
type: 'DELETE',
});

await saveChunk.call(this, parsed, 0, response.version);
await saveChunk.call(this, parsed, 0, 0);
}

async function onload(overlay, text) {
Expand Down
2 changes: 0 additions & 2 deletions cvat/apps/engine/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def get(jid):
return annotation.to_client()

@silk_profile(name="Save job")
@plugin_decorator
@transaction.atomic
def save_job(jid, data):
"""
Expand Down Expand Up @@ -1504,7 +1503,6 @@ def init_from_db(self):
self.points = annotation.points
self.points_paths = annotation.points_paths

@plugin_decorator
def _dump(tid, data_format, scheme, host, plugin_meta_data):
# For big tasks dump function may run for a long time and
# we dont need to acquire lock after _AnnotationForTask instance
Expand Down
4 changes: 3 additions & 1 deletion cvat/apps/engine/annotation_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def put_job_data(pk, data):
return annotation.data

@silk_profile(name="UPDATE job data")
@plugin_decorator
@transaction.atomic
def patch_job_data(pk, data, action):
annotation = JobAnnotation(pk)
Expand Down Expand Up @@ -110,6 +111,7 @@ def delete_task_data(pk):
annotation = TaskAnnotation(pk)
annotation.delete()


def dump_task_data(pk, file_path, scheme, host, query_params):
# For big tasks dump function may run for a long time and
# we dont need to acquire lock after _AnnotationForTask instance
Expand Down Expand Up @@ -608,7 +610,7 @@ def init_from_db(self):
self.db_task.overlap)
self._merge_tracks(annotation.data["tracks"], db_segment.start_frame,
self.db_task.overlap)

def _merge_tags(self, tags, start_frame, overlap):
# FIXME: implement merge algorithm here
self.data["tags"].extend(tags)
Expand Down
18 changes: 18 additions & 0 deletions cvat/apps/engine/migrations/0019_auto_20190404_1906.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-04-04 16:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('engine', '0018_remove_job_max_shape_id'),
]

operations = [
migrations.AlterField(
model_name='task',
name='overlap',
field=models.PositiveIntegerField(null=True),
),
]
2 changes: 1 addition & 1 deletion cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Task(models.Model):
bug_tracker = models.CharField(max_length=2000, blank=True, default="")
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now_add=True)
overlap = models.PositiveIntegerField(default=0)
overlap = models.PositiveIntegerField(null=True)
# Zero means that there are no limits (default)
segment_size = models.PositiveIntegerField(default=0)
z_order = models.BooleanField(default=False)
Expand Down
17 changes: 11 additions & 6 deletions cvat/apps/engine/static/engine/js/annotationParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class AnnotationParser {
_getAttributeList(shape, labelId) {
let attributeDict = {};
let attributes = shape.getElementsByTagName('attribute');
for (let attribute of attributes ) {
for (let attribute of attributes) {
let [id, value] = this._getAttribute(labelId, attribute);
attributeDict[id] = value;
}
Expand Down Expand Up @@ -314,6 +314,10 @@ class AnnotationParser {
shapes: [],
};

if (path.frame < this._startFrame || path.frame > this._stopFrame) {
continue;
}

for (let shape of parsed[type]) {
const keyFrame = +shape.getAttribute('keyframe');
const outside = +shape.getAttribute('outside');
Expand All @@ -325,31 +329,32 @@ class AnnotationParser {
Ignore all frames less then start.
Ignore all frames more then stop.
*/
const significant = keyFrame || frame === this._startFrame;
const significant = (keyFrame || frame === this._startFrame)
&& frame >= this._startFrame && frame <= this._stopFrame;

if (significant) {
const attributeList = this._getAttributeList(shape, labelId);
const shapeAttributes = [];
const pathAttributes = [];

for (let attr of attributeList) {
const attrInfo = this._labelsInfo.attrInfo(attr.id);
const attrInfo = this._labelsInfo.attrInfo(attr.spec_id);
if (attrInfo.mutable) {
shapeAttributes.push({
id: attr.id,
spec_id: attr.spec_id,
value: attr.value,
});
}
else {
pathAttributes.push({
id: attr.id,
spec_id: attr.spec_id,
value: attr.value,
});
}
}
path.attributes = pathAttributes;

if (type === 'boxes') {
if (type === 'box') {
let [points, occluded, z_order] = this._getBoxPosition(shape, Math.clamp(frame, this._startFrame, this._stopFrame));
path.shapes.push({
attributes: shapeAttributes,
Expand Down
7 changes: 6 additions & 1 deletion cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,16 @@ def _save_task_to_db(db_task):
job.meta['status'] = 'Task is being saved in database'
job.save_meta()

default_overlap = 5 if db_task.mode == 'interpolation' else 0
if db_task.overlap is None:
db_task.overlap = default_overlap
db_task.overlap = min(db_task.overlap, db_task.size - 1)

segment_size = db_task.segment_size
if segment_size == 0:
segment_size = db_task.size

for x in range(0, db_task.size, segment_size):
for x in range(0, db_task.size, segment_size - db_task.overlap):
start_frame = x
stop_frame = min(x + segment_size - 1, db_task.size - 1)
slogger.glob.info("New segment for task #{}: start_frame = {}, \
Expand Down
Loading

0 comments on commit 7ce6eb6

Please sign in to comment.