Skip to content

Commit

Permalink
Fix diff cli, add confusion matrices for polygons and masks (cvat-ai#117
Browse files Browse the repository at this point in the history
)

* Fix diff cli, add confusion matrices for polygons and masks

- Fixed diff invocation problem
- Added test
- Added confusion matrices for polygons ans masks
- Added support for mismathing classes
- Fixed ProjectDataset.Subset

* Update changelog
  • Loading branch information
Maxim Zhiltsov authored Feb 26, 2021
1 parent 7e7adf6 commit 7406fe8
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 156 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Laziness, source caching, tracking of changes and partial updating for `Dataset` (<https://github.com/openvinotoolkit/datumaro/pull/102>)
- `Market-1501` dataset format (<https://github.com/openvinotoolkit/datumaro/pull/108>)
- `LFW` dataset format (<https://github.com/openvinotoolkit/datumaro/pull/110>)
- Support of polygons' and masks' confusion matrices and mismathing classes in `diff` command (<https://github.com/openvinotoolkit/datumaro/pull/117>)

### Changed
- OpenVINO model launcher is updated for OpenVINO r2021.1 (<https://github.com/openvinotoolkit/datumaro/pull/100>)
Expand All @@ -25,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- High memory consumption and low performance of mask import/export, #53 (<https://github.com/openvinotoolkit/datumaro/pull/101>)
- Masks, covered by class 0 (background), should be exported with holes inside (<https://github.com/openvinotoolkit/datumaro/pull/104>)
- `diff` command invocation problem with missing class methods (<https://github.com/openvinotoolkit/datumaro/pull/117>)

### Security
-
Expand Down
23 changes: 11 additions & 12 deletions datumaro/cli/contexts/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from datumaro.components.project import \
PROJECT_DEFAULT_CONFIG as DEFAULT_CONFIG
from datumaro.components.project import Environment, Project
from datumaro.util import error_rollback

from ...util import (CliException, MultilineFormatter, add_subparser,
make_file_name)
from ...util.project import generate_next_file_name, load_project
from .diff import DiffVisualizer
from .diff import DatasetDiffVisualizer


def build_create_parser(parser_ctor=argparse.ArgumentParser):
Expand Down Expand Up @@ -506,8 +507,8 @@ def build_diff_parser(parser_ctor=argparse.ArgumentParser):
parser.add_argument('-o', '--output-dir', dest='dst_dir', default=None,
help="Directory to save comparison results (default: do not save)")
parser.add_argument('-v', '--visualizer',
default=DiffVisualizer.DEFAULT_FORMAT,
choices=[f.name for f in DiffVisualizer.Format],
default=DatasetDiffVisualizer.DEFAULT_FORMAT.name,
choices=[f.name for f in DatasetDiffVisualizer.OutputFormat],
help="Output format (default: %(default)s)")
parser.add_argument('--iou-thresh', default=0.5, type=float,
help="IoU match threshold for detections (default: %(default)s)")
Expand All @@ -521,6 +522,7 @@ def build_diff_parser(parser_ctor=argparse.ArgumentParser):

return parser

@error_rollback('on_error', implicit=True)
def diff_command(args):
first_project = load_project(args.project_dir)
second_project = load_project(args.other_project_dir)
Expand All @@ -540,17 +542,14 @@ def diff_command(args):
dst_dir = osp.abspath(dst_dir)
log.info("Saving diff to '%s'" % dst_dir)

dst_dir_existed = osp.exists(dst_dir)
try:
visualizer = DiffVisualizer(save_dir=dst_dir, comparator=comparator,
output_format=args.visualizer)
visualizer.save_dataset_diff(
if not osp.exists(dst_dir):
on_error.do(shutil.rmtree, dst_dir, ignore_errors=True)

with DatasetDiffVisualizer(save_dir=dst_dir, comparator=comparator,
output_format=args.visualizer) as visualizer:
visualizer.save(
first_project.make_dataset(),
second_project.make_dataset())
except BaseException:
if not dst_dir_existed and osp.isdir(dst_dir):
shutil.rmtree(dst_dir, ignore_errors=True)
raise

return 0

Expand Down
Loading

0 comments on commit 7406fe8

Please sign in to comment.