-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Feature] Add SRFacicalLandmarkDataset. #329
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os.path as osp | ||
|
||
import numpy as np | ||
|
||
from .base_sr_dataset import BaseSRDataset | ||
from .registry import DATASETS | ||
|
||
|
||
@DATASETS.register_module() | ||
class SRFacicalLandmarkDataset(BaseSRDataset): | ||
"""Facical image and landmark dataset with an annotation file for image | ||
restoration. | ||
|
||
The dataset loads gt (Ground-Truth) image, shape of image, face box, and | ||
landmark. Applies specified transforms and finally returns a dict | ||
containing paired data and other information. | ||
|
||
This is the "annotation file mode": | ||
Each dict in the annotation list contains the image names, image shape, | ||
face box, and landmark. | ||
|
||
Annotation file is a `npy` file, which contains a list of dict. | ||
Example of an annotation file: | ||
|
||
:: | ||
|
||
dict1(file=*, bbox=*, shape=*, landmark=*) | ||
dict2(file=*, bbox=*, shape=*, landmark=*) | ||
|
||
Args: | ||
gt_folder (str | :obj:`Path`): Path to a gt folder. | ||
ann_file (str | :obj:`Path`): Path to the annotation file. | ||
pipeline (list[dict | callable]): A sequence of data transformations. | ||
scale (int): Upsampling scale ratio. | ||
test_mode (bool): Store `True` when building test dataset. | ||
Default: `False`. | ||
""" | ||
|
||
def __init__(self, gt_folder, ann_file, pipeline, scale, test_mode=False): | ||
super().__init__(pipeline, scale, test_mode) | ||
self.gt_folder = str(gt_folder) | ||
self.ann_file = str(ann_file) | ||
self.data_infos = self.load_annotations() | ||
|
||
def load_annotations(self): | ||
"""Load annoations for SR dataset. | ||
|
||
Annotation file is a `npy` file, which contains a list of dict. | ||
|
||
It loads the GT image path and landmark from the annotation file. | ||
Each dict in the annotation file contains the image names, image | ||
shape (usually for gt), bbox and landmark. | ||
|
||
Returns: | ||
dict: Returned dict for GT and landmark. | ||
Contains: gt_path, bbox, shape, landmark. | ||
""" | ||
data_infos = np.load(self.ann_file, allow_pickle=True) | ||
for data_info in data_infos: | ||
data_info['gt_path'] = osp.join(self.gt_folder, | ||
data_info['gt_path']) | ||
|
||
return data_infos |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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.
Use
mmcv.load
. Benefit: it will support json automatically.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.
But it doesn't support "npy" file, and here we don't need JSON data.
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.
I see.