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

Fix frame step export for image tasks #1615

Merged
merged 7 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-

### Fixed
- Problem with exported frame stepped image task (<https://github.com/opencv/cvat/issues/1613>)
- Fixed dataset filter item representation for imageless dataset items (<https://github.com/opencv/cvat/pull/1593>)
- Fixed interpreter crash when trying to import `tensorflow` with no AVX instructions available (<https://github.com/opencv/cvat/pull/1567>)
- Kibana wrong working time calculation with new annotation UI use (<https://github.com/opencv/cvat/pull/1654>)
Expand Down Expand Up @@ -85,6 +86,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- A problem with mask to polygons conversion when polygons are too small (<https://github.com/opencv/cvat/pull/1581>)
- Unable to upload video with uneven size (<https://github.com/opencv/cvat/pull/1594>)
- Fixed an issue with `z_order` having no effect on segmentations (<https://github.com/opencv/cvat/pull/1589>)

### Security
- Permission group whitelist check for analytics view (<https://github.com/opencv/cvat/pull/1608>)

## [1.0.0-beta.2] - 2020-04-30
Expand Down
37 changes: 18 additions & 19 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,21 @@ def _get_mutable_attribute_id(self, label_id, attribute_name):
def _get_immutable_attribute_id(self, label_id, attribute_name):
return self._get_attribute_id(label_id, attribute_name, 'immutable')

def abs_frame_id(self, relative_id):
return relative_id * self._frame_step + self._db_task.data.start_frame

def rel_frame_id(self, absolute_id):
return (absolute_id - self._db_task.data.start_frame) // self._frame_step

def _init_frame_info(self):
if hasattr(self._db_task.data, 'video'):
self._frame_info = {frame: {
"path": "frame_{:06d}".format(
self._db_task.data.start_frame + frame * self._frame_step),
"path": "frame_{:06d}".format(self.abs_frame_id(frame)),
"width": self._db_task.data.video.width,
"height": self._db_task.data.video.height,
} for frame in range(self._db_task.data.size)}
else:
self._frame_info = {db_image.frame: {
self._frame_info = {self.rel_frame_id(db_image.frame): {
"path": db_image.path,
"width": db_image.width,
"height": db_image.height,
Expand Down Expand Up @@ -193,8 +198,7 @@ def _export_attributes(self, attributes):
def _export_tracked_shape(self, shape):
return TaskData.TrackedShape(
type=shape["type"],
frame=self._db_task.data.start_frame +
shape["frame"] * self._frame_step,
frame=self.abs_frame_id(shape["frame"]),
label=self._get_label_name(shape["label_id"]),
points=shape["points"],
occluded=shape["occluded"],
Expand All @@ -210,8 +214,7 @@ def _export_labeled_shape(self, shape):
return TaskData.LabeledShape(
type=shape["type"],
label=self._get_label_name(shape["label_id"]),
frame=self._db_task.data.start_frame +
shape["frame"] * self._frame_step,
frame=self.abs_frame_id(shape["frame"]),
points=shape["points"],
occluded=shape["occluded"],
z_order=shape.get("z_order", 0),
Expand All @@ -221,8 +224,7 @@ def _export_labeled_shape(self, shape):

def _export_tag(self, tag):
return TaskData.Tag(
frame=self._db_task.data.start_frame +
tag["frame"] * self._frame_step,
frame=self.abs_frame_id(tag["frame"]),
label=self._get_label_name(tag["label_id"]),
group=tag.get("group", 0),
attributes=self._export_attributes(tag["attributes"]),
Expand All @@ -232,7 +234,7 @@ def group_by_frame(self, include_empty=False):
frames = {}
def get_frame(idx):
frame_info = self._frame_info[idx]
frame = self._db_task.data.start_frame + idx * self._frame_step
frame = self.abs_frame_id(idx)
if frame not in frames:
frames[frame] = TaskData.Frame(
idx=idx,
Expand Down Expand Up @@ -299,8 +301,7 @@ def meta(self):
def _import_tag(self, tag):
_tag = tag._asdict()
label_id = self._get_label_id(_tag.pop('label'))
_tag['frame'] = (int(_tag['frame']) -
self._db_task.data.start_frame) // self._frame_step
_tag['frame'] = self.rel_frame_id(int(_tag['frame']))
_tag['label_id'] = label_id
_tag['attributes'] = [self._import_attribute(label_id, attrib)
for attrib in _tag['attributes']
Expand All @@ -316,8 +317,7 @@ def _import_attribute(self, label_id, attribute):
def _import_shape(self, shape):
_shape = shape._asdict()
label_id = self._get_label_id(_shape.pop('label'))
_shape['frame'] = (int(_shape['frame']) -
self._db_task.data.start_frame) // self._frame_step
_shape['frame'] = self.rel_frame_id(int(_shape['frame']))
_shape['label_id'] = label_id
_shape['attributes'] = [self._import_attribute(label_id, attrib)
for attrib in _shape['attributes']
Expand All @@ -327,14 +327,13 @@ def _import_shape(self, shape):
def _import_track(self, track):
_track = track._asdict()
label_id = self._get_label_id(_track.pop('label'))
_track['frame'] = (min(int(shape.frame) for shape in _track['shapes']) -
self._db_task.data.start_frame) // self._frame_step
_track['frame'] = self.rel_frame_id(
min(int(shape.frame) for shape in _track['shapes']))
_track['label_id'] = label_id
_track['attributes'] = []
_track['shapes'] = [shape._asdict() for shape in _track['shapes']]
for shape in _track['shapes']:
shape['frame'] = (int(shape['frame']) - \
self._db_task.data.start_frame) // self._frame_step
shape['frame'] = self.rel_frame_id(int(shape['frame']))
_track['attributes'] = [self._import_attribute(label_id, attrib)
for attrib in shape['attributes']
if self._get_immutable_attribute_id(label_id, attrib.name)]
Expand Down Expand Up @@ -567,7 +566,7 @@ def import_dm_annotations(dm_dataset, task_data):
label_cat = dm_dataset.categories()[datumaro.AnnotationType.label]

for item in dm_dataset:
frame_number = match_frame(item, task_data)
frame_number = task_data.abs_frame_id(match_frame(item, task_data))

# do not store one-item groups
group_map = {0: 0}
Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/dataset_manager/formats/mot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _import(src_file, task_data):

for item in dataset:
item = item.wrap(id=int(item.id) - 1) # NOTE: MOT frames start from 1
frame_id = match_frame(item, task_data)
frame_number = task_data.abs_frame_id(match_frame(item, task_data))

for ann in item.annotations:
if ann.type != datumaro.AnnotationType.bbox:
Expand All @@ -57,7 +57,7 @@ def _import(src_file, task_data):
outside=False,
keyframe=False,
z_order=ann.z_order,
frame=frame_id,
frame=frame_number,
attributes=[],
)

Expand Down