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

[Datumaro] Add merge command with segment intersection #1695

Merged
merged 15 commits into from
Aug 17, 2020

Conversation

zhiltsov-max
Copy link
Contributor

@zhiltsov-max zhiltsov-max commented Jun 10, 2020

Motivation and context

  • Added a command to merge any number of annotation datasets.
    • Annotations are matched by area, where it makes sense
    • Attributes and labels are merged by voting

If you want to test:

datum merge <project1> <project2> ...

Labels in the datasets must match.

Example (requires openvino):

interp.py

from datumaro.components.extractor import *

conf_thresh = 0.5

def process_outputs(inputs, outputs):
     # inputs = model input, array or images, shape = (N, C, H, W)
     # outputs = model output, shape = (N, 1, K, 7)
     # results = conversion result, [ [ Annotation, ... ], ... ]
     results = []
     for input, output in zip(inputs, outputs):
          input_height, input_width = input.shape[:2]
          detections = output[0]
          image_results = []
          for i, det in enumerate(detections):
               label = int(det[1])
               conf = float(det[2])
               if conf <= conf_thresh:
                    continue

               x = max(int(det[3] * input_width), 0)
               y = max(int(det[4] * input_height), 0)
               w = min(int(det[5] * input_width - x), input_width)
               h = min(int(det[6] * input_height - y), input_height)
               image_results.append(Bbox(x, y, w, h,
                    label=label, attributes={'score': conf} ))

               results.append(image_results)

     return results

def get_categories():
     label_categories = LabelCategories()
     label_categories.add('background')
     label_categories.add('face')
     return { AnnotationType.label: label_categories }

Face detection example

# create a project from some images with faces
datum project import -i images/ -f image_dir -o test_project
cd test_project

# annotate with models
# https://github.com/opencv/open_model_zoo/blob/master/models/intel/face-detection-adas-0001/model.yml
# https://github.com/opencv/open_model_zoo/blob/master/models/intel/face-detection-retail-0004/model.yml
# interp.py almost exactly like in the documentation https://github.com/opencv/cvat/blob/develop/datumaro/docs/user_manual.md#register-model
wget https://download.01.org/opencv/2020/openvinotoolkit/2020.3/open_model_zoo/models_bin/1/face-detection-adas-0001/FP32/face-detection-adas-0001.xml
wget https://download.01.org/opencv/2020/openvinotoolkit/2020.3/open_model_zoo/models_bin/1/face-detection-adas-0001/FP32/face-detection-adas-0001.bin
wget https://download.01.org/opencv/2020/openvinotoolkit/2020.3/open_model_zoo/models_bin/1/face-detection-retail-0004/FP32/face-detection-retail-0004.xml
wget https://download.01.org/opencv/2020/openvinotoolkit/2020.3/open_model_zoo/models_bin/1/face-detection-retail-0004/FP32/face-detection-retail-0004.bin
datum model add -l open_vino -- -w face-detection-retail-0004.bin -d face-detection-retail-0004.xml -i interp.py
datum model add -l open_vino -- -w face-detection-adas-0001.bin -d face-detection-adas-0001.xml -i interp.py
datum model run -m model-1
datum model run -m model-2

# merge
datum --loglevel debug merge ./test_project-inference.1 ./test_project-inference.2

# compare
datum quality -p test_project-inference.1 --inference-path test_project-inference.2

# just show the boxes
datum project transform -p merged -t boxes_to_masks
datum project export -p undefined-boxes_to_masks/ -f voc_segmentation -e '/item/annotation' --filter-mode i+a -- --save-images

How has this been tested?

Manual test, unit tests.

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT

@zhiltsov-max zhiltsov-max changed the base branch from develop to zm/ann-quality-main June 10, 2020 17:28
@zhiltsov-max zhiltsov-max changed the base branch from zm/ann-quality-main to develop June 10, 2020 17:33
@zhiltsov-max zhiltsov-max changed the base branch from develop to zm/ann-quality-main June 10, 2020 17:33
@zhiltsov-max zhiltsov-max changed the base branch from zm/ann-quality-main to develop June 10, 2020 17:34
@coveralls
Copy link

coveralls commented Jun 10, 2020

Pull Request Test Coverage Report for Build 6926

  • 660 of 792 (83.33%) changed or added relevant lines in 14 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.8%) to 69.729%

Changes Missing Coverage Covered Lines Changed/Added Lines %
datumaro/datumaro/components/algorithms/rise.py 2 4 50.0%
datumaro/datumaro/cli/util/init.py 2 17 11.76%
datumaro/datumaro/components/operations.py 505 538 93.87%
datumaro/datumaro/util/annotation_util.py 109 142 76.76%
datumaro/datumaro/cli/commands/merge.py 12 61 19.67%
Totals Coverage Status
Change from base Build 6850: 0.8%
Covered Lines: 11722
Relevant Lines: 16356

💛 - Coveralls

@zhiltsov-max zhiltsov-max changed the title [WIP] [Datumaro] Add merge with segment intersection [WIP] [Datumaro] Add merge command with segment intersection Jun 16, 2020
@zhiltsov-max
Copy link
Contributor Author

@azhavoro, @nmanovic, here is something you can test (in the description).

Copy link
Contributor

nmanovic commented Jul 8, 2020

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 1
           

Complexity increasing per file
==============================
- datumaro/datumaro/util/annotation_tools.py  1
- datumaro/datumaro/cli/contexts/project/diff.py  1
- datumaro/datumaro/cli/commands/quality.py  7
- datumaro/datumaro/cli/commands/merge.py  7
         

Complexity decreasing per file
==============================
+ datumaro/datumaro/components/project.py  -3
         

See the complete overview on Codacy

_image = None # TODO: remove after debug
_item = None # TODO: remove after debug
def __call__(self, datasets):
merged = Dataset(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azhavoro
Copy link
Contributor

@zhiltsov-max Could you please update PR? There are many indentation errors in datumaro/datumaro/components/operations.py.

@zhiltsov-max zhiltsov-max changed the title [WIP] [Datumaro] Add merge command with segment intersection [Datumaro] Add merge command with segment intersection Aug 3, 2020
@zhiltsov-max
Copy link
Contributor Author

Finished.

@nmanovic
Copy link
Contributor

nmanovic commented Aug 7, 2020

@zhiltsov-max , need to fix merge conflicts

Copy link
Contributor

@nmanovic nmanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nmanovic nmanovic added this to Reviewer approved in Dataset framework (Datumaro) via automation Aug 17, 2020
@nmanovic nmanovic merged commit 17a5554 into develop Aug 17, 2020
Dataset framework (Datumaro) automation moved this from Reviewer approved to Done Aug 17, 2020
@bsekachev bsekachev deleted the zm/ann-quality-merge branch August 24, 2020 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants