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

Add possibility to merge several classes to dataset scripts #156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion luminoth/tools/dataset/readers/object_detection/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, data_dir, split, year=DEFAULT_YEAR,
for annotation in annotations_json['annotations']:
image_id = annotation['image_id']
x, y, width, height = annotation['bbox']
if not self._merge_classes:
if not self.merge_classes:
try:
label_id = self.classes.index(
category_to_name[annotation['category_id']]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, only_classes=None, only_images=None,

self._limit_examples = limit_examples
self._limit_classes = limit_classes
self._merge_classes = merge_classes
self.merge_classes = merge_classes
random.seed(seed)

self._total = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def iterate(self):
gt_boxes = []

for b in annotation['object']:
if not self._merge_classes:
if not self.merge_classes:
try:
label_id = self.classes.index(b['name'])
except ValueError:
Expand Down
7 changes: 6 additions & 1 deletion luminoth/tools/dataset/writers/object_detection_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ def save(self):

# Save classes in simple json format for later use.
classes_file = os.path.join(self._output_dir, CLASSES_FILENAME)
json.dump(self._reader.classes, tf.gfile.GFile(classes_file, 'w'))
if self._reader.merge_classes:
# Don't assign a name to the class if its a merge of several others
json.dump([''], tf.gfile.GFile(classes_file, 'w'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Have an option to set the class name before merging the pull request.

else:
json.dump(self._reader.classes, tf.gfile.GFile(classes_file, 'w'))

record_file = os.path.join(
self._output_dir, '{}.tfrecords'.format(self._split))
writer = tf.python_io.TFRecordWriter(record_file)
Expand Down