Skip to content

Commit

Permalink
Enhance the error message for datum stats to be more user friendly (#…
Browse files Browse the repository at this point in the history
…1069)

- Ticket no. 112203
- Improve the error message for users encountered in the following CLI
use case:

```console
(datumaro) vinnamki@vinnamki:~/datumaro/ws_datum/stats$ datum project create
(datumaro) vinnamki@vinnamki:~/datumaro/ws_datum/stats$ datum project import -n eurosat -f imagenet_txt /home/vinnamki/datumaro/tfdseurosat-imagenet_txt.1
(datumaro) vinnamki@vinnamki:~/datumaro/ws_datum/stats$ datum project import -n uc_merced -f imagenet_txt /home/vinnamki/datumaro/tfdsuc_merced-imagenet_txt
```
**(Before)**
```console
(datumaro) vinnamki@vinnamki:~/datumaro/ws_datum/stats$ datum stats
2023-06-28 17:09:27,574 ERROR: Failed to parse revspec:
  Merging of datasets with different categories is only allowed in 'merge' command.
  Path project doesn't exist
```
**(After)**
```console
(datumaro) vinnamki@vinnamki:~/datumaro/ws_datum/stats$ datum stats
2023-06-28 17:55:20,580 ERROR: There are more than two sources with heterogeneous categories in the project. This prevents computing the statistics of the merged one. Please specify one of the sources in the project (['eurosat', 'uc_merced']), such as `datum stats eurosat`
```

Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
  • Loading branch information
vinnamkim committed Jul 3, 2023
1 parent 0758a58 commit 6070ff2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(<https://github.com/openvinotoolkit/datumaro/pull/1055>)
- Add CVAT data format document
(<https://github.com/openvinotoolkit/datumaro/pull/1060>)
- Enhance the error message for datum stats to be more user friendly
(<https://github.com/openvinotoolkit/datumaro/pull/1069>)

### Bug fixes
- Fix warnings in test_visualizer.py
Expand Down
19 changes: 17 additions & 2 deletions src/datumaro/cli/commands/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import argparse
import logging as log

from datumaro.components.errors import ProjectNotFoundError
from datumaro.cli.util.errors import CliException, WrongRevpathError
from datumaro.components.errors import ConflictingCategoriesError, ProjectNotFoundError
from datumaro.components.operations import compute_ann_statistics, compute_image_statistics
from datumaro.util import dump_json_file, str_to_bool
from datumaro.util.scope import scope_add, scoped
Expand Down Expand Up @@ -87,7 +88,21 @@ def stats_command(args):
if args.project_dir:
raise

dataset, target_project = parse_full_revpath(args.target, project)
try:
dataset, target_project = parse_full_revpath(args.target, project)
except WrongRevpathError as e:
for p in e.problems:
if isinstance(p, ConflictingCategoriesError):
src_names = [src for src in project.working_tree.sources]
raise CliException(
"There are more than two sources with heterogeneous categories in the project. "
"This prevents computing the statistics of the merged one. "
f"Please specify one of the sources in the project ({src_names}), "
f"such as `datum stats {src_names[0]}`"
) from e

raise e

if target_project:
scope_add(target_project)

Expand Down

0 comments on commit 6070ff2

Please sign in to comment.