Skip to content
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 down_sampling.py for generating LQ image from GT image. #222

Merged
merged 5 commits into from
Mar 15, 2021

Conversation

Yshuo-Li
Copy link
Collaborator

Add down_sampling.py for generating LQ image from GT image, which is required in Learning Continuous Image Representation with Local Implicit Image Function

Args:
scale_min (int): The minimum of upsampling scale. Default: 1.
scale_max (int): The maximum of upsampling scale. Default: 4.
inp_size (int): The input size, i.e. cropped lr patch size.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inp_size -> input_size

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or patch_size?


Args:
scale_min (int): The minimum of upsampling scale. Default: 1.
scale_max (int): The maximum of upsampling scale. Default: 4.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this min to max range inclusive or exclusive


Args:
results (dict): A dict containing the necessary information and
data for augmentation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly specify which keys are required, which are modified

if isinstance(size, int):
size = (size, size)
if isinstance(img, np.ndarray):
return np.asarray(Image.fromarray(img).resize(size, Image.BICUBIC))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Will cv2.resize or mmcv.imresize work here?
  • Is the PIL image a hard requirement

if isinstance(size, int):
size = (size, size)
if isinstance(img, np.ndarray):
return np.asarray(Image.fromarray(img).resize(size, Image.BICUBIC))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Will cv2.resize or mmcv.imresize work here?
  • Is the PIL image a hard requirement?

@codecov
Copy link

codecov bot commented Mar 13, 2021

Codecov Report

Merging #222 (3292f80) into master (79f74a1) will decrease coverage by 0.01%.
The diff coverage is 89.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #222      +/-   ##
==========================================
- Coverage   81.71%   81.69%   -0.02%     
==========================================
  Files         148      149       +1     
  Lines        7055     7102      +47     
  Branches     1047     1052       +5     
==========================================
+ Hits         5765     5802      +37     
- Misses       1171     1179       +8     
- Partials      119      121       +2     
Flag Coverage Δ
unittests 81.69% <89.36%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmedit/datasets/pipelines/down_sampling.py 89.13% <89.13%> (ø)
mmedit/datasets/pipelines/__init__.py 100.00% <100.00%> (ø)
mmedit/models/common/generation_model_utils.py 95.19% <0.00%> (-4.81%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 79f74a1...18b8c70. Read the comment docs.

Scale will be in the range of [scale_min, scale_max).
"""

def __init__(self, scale_min=1, scale_max=4, patch_size=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add interpolation and backend here, and pass them to resize_fn

modified 'gt', supplement 'lq' and 'scale' to keys.
"""
img = results['gt']
scale = random.uniform(self.scale_min, self.scale_max)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use np.random



@PIPELINES.register_module()
class DownSampling:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DownSampling -> RandomDownSampling

"""Generate LQ image from GT (and crop).

Args:
scale_min (int): The minimum of upsampling scale, inclusive.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int -> float


@PIPELINES.register_module()
class DownSampling:
"""Generate LQ image from GT (and crop).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give a detailed description here. e.g. it randomly pick a scale

if isinstance(size, int):
size = (size, size)
if isinstance(img, np.ndarray):
return imresize(img, size, interpolation='bicubic', backend='pillow')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not hardcode bicubic here

return imresize(img, size, interpolation='bicubic', backend='pillow')
elif isinstance(img, torch.Tensor):
image = imresize(
img.numpy(), size, interpolation='bicubic', backend='pillow')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@innerlee innerlee merged commit ad517d4 into open-mmlab:master Mar 15, 2021
@Yshuo-Li Yshuo-Li deleted the down_sampling branch April 8, 2021 08:18
Yshuo-Li added a commit to Yshuo-Li/mmediting that referenced this pull request Jul 15, 2022
…ab#222)

* Add down_sampling.py for generating LQ image from GT image, which is required in LIIF.

* Add '__repr__' and test_down_sampling.py.

* Add docstring, rename parameter and change the function of resize.

* Fine-tuning code and docstring of RandomDownSampling class.

* Remove hardcode of bicubic and pillow.

Co-authored-by: 李尹硕 <SENSETIME\[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants