-
Notifications
You must be signed in to change notification settings - Fork 138
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
Label "face" for bounding boxes in Wider Face #215
Merged
Merged
Changes from 3 commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ class WiderFacePath: | |
IMAGES_DIR_NO_LABEL = 'no_label' | ||
BBOX_ATTRIBUTES = ['blur', 'expression', 'illumination', | ||
'occluded', 'pose', 'invalid'] | ||
DEFAULT_LABEL = 'face' | ||
|
||
class WiderFaceExtractor(SourceExtractor): | ||
def __init__(self, path, subset=None): | ||
|
@@ -40,12 +41,14 @@ def __init__(self, path, subset=None): | |
|
||
def _load_categories(self): | ||
label_cat = LabelCategories() | ||
|
||
label_cat.add(WiderFacePath.DEFAULT_LABEL) | ||
path = osp.join(self._dataset_dir, WiderFacePath.LABELS_FILE) | ||
if osp.isfile(path): | ||
with open(path, encoding='utf-8') as labels_file: | ||
for line in labels_file: | ||
label_cat.add(line.strip()) | ||
label_name = line.strip() | ||
if label_name != WiderFacePath.DEFAULT_LABEL: | ||
label_cat.add(label_name) | ||
else: | ||
subset_path = osp.join(self._dataset_dir, | ||
WiderFacePath.SUBSET_DIR + self._subset, | ||
|
@@ -56,12 +59,15 @@ def _load_categories(self): | |
images_dir != WiderFacePath.IMAGES_DIR_NO_LABEL: | ||
if '--' in images_dir: | ||
images_dir = images_dir.split('--')[1] | ||
label_cat.add(images_dir) | ||
|
||
if images_dir != WiderFacePath.DEFAULT_LABEL: | ||
label_cat.add(images_dir) | ||
if len(label_cat) == 1: | ||
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. Should only the default label be removed when there was a file? |
||
label_cat = LabelCategories() | ||
return { AnnotationType.label: label_cat } | ||
|
||
def _load_items(self, path): | ||
items = {} | ||
label_categories = self._categories[AnnotationType.label] | ||
|
||
with open(path, 'r', encoding='utf-8') as f: | ||
lines = f.readlines() | ||
|
@@ -73,6 +79,7 @@ def _load_items(self, path): | |
for line_idx in line_ids: | ||
image_path = lines[line_idx].strip() | ||
item_id = osp.splitext(image_path)[0] | ||
item_id = item_id.replace('\\', '/') | ||
|
||
image_path = osp.join(self._dataset_dir, | ||
WiderFacePath.SUBSET_DIR + self._subset, | ||
|
@@ -84,9 +91,9 @@ def _load_items(self, path): | |
if '--' in label_name: | ||
label_name = label_name.split('--')[1] | ||
if label_name != WiderFacePath.IMAGES_DIR_NO_LABEL: | ||
label = \ | ||
self._categories[AnnotationType.label].find(label_name)[0] | ||
annotations.append(Label(label=label)) | ||
label = label_categories.find(label_name)[0] | ||
if label != None: | ||
annotations.append(Label(label=label)) | ||
item_id = item_id[len(item_id.split('/')[0]) + 1:] | ||
|
||
items[item_id] = DatasetItem(id=item_id, subset=self._subset, | ||
|
@@ -101,21 +108,22 @@ def _load_items(self, path): | |
for bbox in bbox_lines: | ||
bbox_list = bbox.split() | ||
if 4 <= len(bbox_list): | ||
attributes = {} | ||
label = None | ||
label = label_categories.find(WiderFacePath.DEFAULT_LABEL)[0] | ||
if len(bbox_list) == 5 or len(bbox_list) == 11: | ||
if len(bbox_list) == 5: | ||
label_name = bbox_list[4] | ||
else: | ||
label_name = bbox_list[10] | ||
label = \ | ||
self._categories[AnnotationType.label].find(label_name)[0] | ||
label_name = bbox_list[-1] | ||
label = label_categories.find(label_name)[0] | ||
if label == None and len(label_categories) == 0: | ||
label_categories.add(WiderFacePath.DEFAULT_LABEL) | ||
label = label_categories.find(WiderFacePath.DEFAULT_LABEL)[0] | ||
|
||
attributes = {} | ||
if 10 <= len(bbox_list): | ||
i = 4 | ||
for attr in WiderFacePath.BBOX_ATTRIBUTES: | ||
if bbox_list[i] != '-': | ||
attributes[attr] = bbox_list[i] | ||
i += 1 | ||
|
||
annotations.append(Bbox( | ||
float(bbox_list[0]), float(bbox_list[1]), | ||
float(bbox_list[2]), float(bbox_list[3]), | ||
|
@@ -180,7 +188,8 @@ def apply(self): | |
wider_attr += '- ' | ||
if 0 < attr_counter: | ||
wider_annotation += wider_attr | ||
if bbox.label is not None: | ||
if label_categories[bbox.label].name != WiderFacePath.DEFAULT_LABEL and \ | ||
bbox.label is not None: | ||
wider_annotation += '%s' % label_categories[bbox.label].name | ||
wider_annotation += '\n' | ||
|
||
|
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
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.
Should this label be included if there is a file?
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.
You're right. This shouldn't work for a label file. Thanks.