-
Notifications
You must be signed in to change notification settings - Fork 398
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
joaqo
wants to merge
2
commits into
master
Choose a base branch
from
add_merge_classes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ def get_output_subfolder(only_classes, only_images, limit_examples, | |
Returns: subfolder name for records | ||
""" | ||
if only_classes is not None: | ||
return 'classes-{}'.format(only_classes) | ||
return 'classes-{}'.format('-'.join(only_classes)) | ||
elif only_images is not None: | ||
return 'only-{}'.format(only_images) | ||
elif limit_examples is not None and limit_classes is not None: | ||
|
@@ -30,16 +30,17 @@ def get_output_subfolder(only_classes, only_images, limit_examples, | |
@click.option('--data-dir', help='Where to locate the original data.') | ||
@click.option('--output-dir', help='Where to save the transformed data.') | ||
@click.option('splits', '--split', required=True, multiple=True, help='Which splits to transform.') # noqa | ||
@click.option('--only-classes', help='Whitelist of classes.') | ||
@click.option('--only-classes', multiple=True, help='Whitelist of classes.') | ||
@click.option('--merge-classes', help='Merge all classes into a single class') | ||
@click.option('--only-images', help='Create dataset with specific examples.') | ||
@click.option('--limit-examples', type=int, help='Limit dataset with to the first `N` examples.') # noqa | ||
@click.option('--limit-classes', type=int, help='Limit dataset with `N` random classes.') # noqa | ||
@click.option('--seed', type=int, help='Seed used for picking random classes.') | ||
@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, limit_classes, seed, overrides, | ||
debug): | ||
merge_classes, only_images, limit_examples, limit_classes, seed, | ||
overrides, debug): | ||
""" | ||
Prepares dataset for ingestion. | ||
|
||
|
@@ -67,16 +68,18 @@ def transform(dataset_reader, data_dir, output_dir, splits, only_classes, | |
# All splits must have a consistent set of classes. | ||
classes = None | ||
|
||
merge_classes = merge_classes in ('True', 'true', 'TRUE') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use click types instead. |
||
|
||
reader_kwargs = parse_override(overrides) | ||
|
||
try: | ||
for split in splits: | ||
# Create instance of reader. | ||
split_reader = reader( | ||
data_dir, split, | ||
only_classes=only_classes, only_images=only_images, | ||
limit_examples=limit_examples, limit_classes=limit_classes, | ||
seed=seed, **reader_kwargs | ||
only_classes=only_classes, merge_classes=merge_classes, | ||
only_images=only_images, limit_examples=limit_examples, | ||
limit_classes=limit_classes, seed=seed, **reader_kwargs | ||
) | ||
|
||
if classes is None: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we name it
--single-class
or--merge-all
to make the fact that only a single class creatd more explicit?