-
Notifications
You must be signed in to change notification settings - Fork 155
Require extensions in in ImageNet_txt #302
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e9fced1
fix imagenet_txt
yasakova-anastasia 8d2275c
fix extractor
yasakova-anastasia 0362661
add extensions for images to annotation file
yasakova-anastasia 6492b64
Merge branch 'develop' into ay/imagenet_txt
yasakova-anastasia 8946edf
update changelog
yasakova-anastasia 39e7456
fix for search images
yasakova-anastasia c6718ce
remove image search
yasakova-anastasia 63b57ba
Update changelog
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ | |
| LabelCategories, AnnotationType, SourceExtractor, Importer | ||
| ) | ||
| from datumaro.components.converter import Converter | ||
| from datumaro.util.image import find_images | ||
|
|
||
|
|
||
| class ImagenetTxtPath: | ||
|
|
@@ -49,26 +48,22 @@ def _load_categories(self, labels): | |
| def _load_items(self, path): | ||
| items = {} | ||
|
|
||
| image_dir = self.image_dir | ||
| if osp.isdir(image_dir): | ||
| images = { osp.splitext(osp.relpath(p, image_dir))[0]: p | ||
| for p in find_images(image_dir, recursive=True) } | ||
| else: | ||
| images = {} | ||
|
|
||
| with open(path, encoding='utf-8') as f: | ||
| for line in f: | ||
| item = line.split('\"') | ||
| if 1 < len(item): | ||
| if len(item) == 3: | ||
| item_id = item[1] | ||
| label_ids = [int(id) for id in item[2].split()] | ||
| item = item[2].split() | ||
| image = item_id + item[0] | ||
| label_ids = [int(id) for id in item[1:]] | ||
| else: | ||
| raise Exception("Line %s: unexpected number " | ||
| "of quotes in filename" % line) | ||
| else: | ||
| item = line.split() | ||
| item_id = item[0] | ||
| item_id = osp.splitext(item[0])[0] | ||
|
Contributor
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. I don't think we can match any extension, if it is specified. |
||
| image = item[0] | ||
| label_ids = [int(id) for id in item[1:]] | ||
|
|
||
| anno = [] | ||
|
|
@@ -79,7 +74,7 @@ def _load_items(self, path): | |
| anno.append(Label(label)) | ||
|
|
||
| items[item_id] = DatasetItem(id=item_id, subset=self._subset, | ||
| image=images.get(item_id), annotations=anno) | ||
| image=osp.join(self.image_dir, image), annotations=anno) | ||
|
|
||
| return items | ||
|
|
||
|
|
@@ -105,18 +100,20 @@ def apply(self): | |
|
|
||
| labels = {} | ||
| for item in subset: | ||
| labels[item.id] = set(p.label for p in item.annotations | ||
| item_id = item.id | ||
| if 1 < len(item_id.split()): | ||
| item_id = '\"' + item_id + '\"' | ||
| item_id += self._find_image_ext(item) | ||
| labels[item_id] = set(p.label for p in item.annotations | ||
| if p.type == AnnotationType.label) | ||
|
|
||
| if self._save_images and item.has_image: | ||
| self._save_image(item, subdir=ImagenetTxtPath.IMAGE_DIR) | ||
|
|
||
| annotation = '' | ||
| for item_id, item_labels in labels.items(): | ||
| if 1 < len(item_id.split()): | ||
| item_id = '\"' + item_id + '\"' | ||
| annotation += '%s %s\n' % ( | ||
| item_id, ' '.join(str(l) for l in item_labels)) | ||
| annotation += '%s %s\n' % (item_id, | ||
| ' '.join(str(l) for l in item_labels)) | ||
|
|
||
| with open(annotation_file, 'w', encoding='utf-8') as f: | ||
| f.write(annotation) | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| 1 0 | ||
| 2 5 | ||
| 3 3 | ||
| 4 5 | ||
| 1.jpg 0 | ||
| 2.jpg 5 | ||
| 3.jpg 3 | ||
| 4.jpg 5 |
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.
Uh oh!
There was an error while loading. Please reload this page.