Skip to content

Commit

Permalink
--max-per-class renamed to --class-examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
dekked authored and nagitsu committed Aug 24, 2018
1 parent a81cbd6 commit 215590f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class ObjectDetectionReader(BaseReader):
number of examples per class in an efficient way.
"""
def __init__(self, only_classes=None, only_images=None,
limit_examples=None, max_per_class=None, **kwargs):
limit_examples=None, class_examples=None, **kwargs):
"""
Args:
- only_classes: string or list of strings used as a class
whitelist.
- only_images: string or list of strings used as a image_id
whitelist.
- limit_examples: max number of examples (images) to use.
- max_per_class: finish when every class has this approximate
- class_examples: finish when every class has this approximate
number of examples.
"""
super(ObjectDetectionReader, self).__init__()
Expand All @@ -55,7 +55,7 @@ def __init__(self, only_classes=None, only_images=None,
self._classes = None

self._limit_examples = limit_examples
self._max_per_class = max_per_class
self._class_examples = class_examples
self._per_class_counter = Counter()
self._maxed_out_classes = set()

Expand Down Expand Up @@ -105,8 +105,8 @@ def _filter_total(self, original_total_records):
if self._limit_examples is not None and self._limit_examples > 0:
return min(self._limit_examples, original_total_records)

# With _max_per_class we potentially have to iterate over every record,
# so we don't know the total ahead of time.
# With _class_examples we potentially have to iterate over every
# record, so we don't know the total ahead of time.

return original_total_records

Expand Down Expand Up @@ -144,7 +144,7 @@ def _stop_iteration(self):
return True

# Every class is maxed out
if self._max_per_class is not None:
if self._class_examples is not None:
return len(self._maxed_out_classes) == len(self.classes)

return False
Expand All @@ -157,14 +157,14 @@ def _will_add_record(self, record):
for box in record['gt_boxes']:
self._per_class_counter[self.classes[box['label']]] += 1

if self._max_per_class is not None:
if self._class_examples is not None:
# Check which classes we have maxed out.
old_maxed_out = self._maxed_out_classes.copy()

self._maxed_out_classes |= set([
label
for label, count in self._per_class_counter.items()
if count >= self._max_per_class
if count >= self._class_examples
])

for label in self._maxed_out_classes - old_maxed_out:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _queue_record(self, records_queue, record):
# example, if "Persons" has been maxed out but "Bus" has not, a new
# image containing only instances of "Person" will not be yielded,
# while an image containing both "Person" and "Bus" instances will.
if self._max_per_class:
if self._class_examples:
labels_in_image = set([
self.classes[bbox['label']] for bbox in record['gt_boxes']
])
Expand Down
6 changes: 3 additions & 3 deletions luminoth/tools/dataset/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
@click.option('--only-classes', help='Keep only examples of these classes. Comma separated list.') # noqa
@click.option('--only-images', help='Create dataset with specific examples. Useful to test model if your model has the ability to overfit.') # noqa
@click.option('--limit-examples', type=int, help='Limit the dataset to the first `N` examples.') # noqa
@click.option('--max-per-class', type=int, help='Finish when every class has at least `N` number of samples. This will be the attempted lower bound; more examples might be added or a class might finish with fewer samples depending on the dataset.') # noqa
@click.option('--class-examples', type=int, help='Finish when every class has at least `N` number of samples. This will be the attempted lower bound; more examples might be added or a class might finish with fewer samples depending on the dataset.') # noqa
@click.option('overrides', '--override', '-o', multiple=True, help='Custom parameters for readers.') # noqa
@click.option('--debug', is_flag=True, help='Set level logging to DEBUG.')
def transform(dataset_reader, data_dir, output_dir, splits, only_classes,
only_images, limit_examples, max_per_class, overrides, debug):
only_images, limit_examples, class_examples, overrides, debug):
"""
Prepares dataset for ingestion.
Expand All @@ -46,7 +46,7 @@ def transform(dataset_reader, data_dir, output_dir, splits, only_classes,
split_reader = reader(
data_dir, split,
only_classes=only_classes, only_images=only_images,
limit_examples=limit_examples, max_per_class=max_per_class,
limit_examples=limit_examples, class_examples=class_examples,
**reader_kwargs
)

Expand Down

0 comments on commit 215590f

Please sign in to comment.