Skip to content

Commit

Permalink
handle image absence
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max committed Aug 3, 2020
1 parent 0974d88 commit cc0fb8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
5 changes: 3 additions & 2 deletions datumaro/datumaro/cli/contexts/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,14 @@ def stats_command(args):
project = load_project(args.project_dir)

dataset = project.make_dataset()
stats = compute_image_statistics(dataset)
stats = {}
stats.update(compute_image_statistics(dataset))
stats.update(compute_ann_statistics(dataset))

dst_file = generate_next_file_name('statistics', ext='.json')
log.info("Writing project statistics to '%s'" % dst_file)
with open(dst_file, 'w') as f:
json.dump(stats, f)
json.dump(stats, f, indent=4, sort_keys=True)

def build_info_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor(help="Get project info",
Expand Down
27 changes: 23 additions & 4 deletions datumaro/datumaro/components/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# SPDX-License-Identifier: MIT

import logging as log
from copy import deepcopy

import cv2
Expand Down Expand Up @@ -94,13 +95,31 @@ def compute_image_statistics(dataset):
}

def _extractor_stats(extractor):
mean, std = mean_std(extractor)
return {
available = True
for item in extractor:
if not (item.has_image and item.image.has_data):
available = False
log.warn("Item %s has no image. Image stats won't be computed",
item.id)
break

stats = {
'images count': len(extractor),
'image mean': [float(n) for n in mean[::-1]],
'image std': [float(n) for n in std[::-1]],
}

if available:
mean, std = mean_std(extractor)
stats.update({
'image mean': [float(n) for n in mean[::-1]],
'image std': [float(n) for n in std[::-1]],
})
else:
stats.update({
'image mean': 'n/a',
'image std': 'n/a',
})
return stats

stats['dataset'].update(_extractor_stats(dataset))

subsets = dataset.subsets() or [None]
Expand Down

0 comments on commit cc0fb8d

Please sign in to comment.