-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 'get_ann_info' to dataset_wrappers #6526
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,30 @@ def get_cat_ids(self, idx): | |
sample_idx = idx - self.cumulative_sizes[dataset_idx - 1] | ||
return self.datasets[dataset_idx].get_cat_ids(sample_idx) | ||
|
||
def get_ann_info(self, idx): | ||
"""Get annotation of concatenated dataset by index. | ||
|
||
This is needed by MixUp. | ||
|
||
Args: | ||
idx (int): Index of data. | ||
|
||
Returns: | ||
dict: Annotation info of specified index. | ||
""" | ||
|
||
if idx < 0: | ||
if -idx > len(self): | ||
raise ValueError( | ||
'absolute value of index should not exceed dataset length') | ||
idx = len(self) + idx | ||
dataset_idx = bisect.bisect_right(self.cumulative_sizes, idx) | ||
if dataset_idx == 0: | ||
sample_idx = idx | ||
else: | ||
sample_idx = idx - self.cumulative_sizes[dataset_idx - 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. line 83-92 can be encapsulated into a function like get_sample_idx and we can use it in many places. 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. This function is only used in two places. Where should this function be placed? |
||
return self.datasets[dataset_idx].get_ann_info(sample_idx) | ||
|
||
def evaluate(self, results, logger=None, **kwargs): | ||
"""Evaluate the results. | ||
|
||
|
@@ -165,6 +189,18 @@ def get_cat_ids(self, idx): | |
|
||
return self.dataset.get_cat_ids(idx % self._ori_len) | ||
|
||
def get_ann_info(self, idx): | ||
"""Get annotation of repeat dataset by index. | ||
|
||
Args: | ||
idx (int): Index of data. | ||
|
||
Returns: | ||
dict: Annotation info of specified index. | ||
""" | ||
|
||
return self.dataset.get_ann_info(idx % self._ori_len) | ||
|
||
def __len__(self): | ||
"""Length after repetition.""" | ||
return self.times * self._ori_len | ||
|
@@ -280,6 +316,18 @@ def __getitem__(self, idx): | |
ori_index = self.repeat_indices[idx] | ||
return self.dataset[ori_index] | ||
|
||
def get_ann_info(self, idx): | ||
"""Get annotation of dataset by index. | ||
|
||
Args: | ||
idx (int): Index of data. | ||
|
||
Returns: | ||
dict: Annotation info of specified index. | ||
""" | ||
ori_index = self.repeat_indices[idx] | ||
return self.dataset.get_ann_info(ori_index) | ||
|
||
def __len__(self): | ||
"""Length after repetition.""" | ||
return len(self.repeat_indices) | ||
|
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.
This line is not necessary.