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 New features: transforms.RandomGrayscale #171

Merged
merged 6 commits into from Mar 11, 2022

Conversation

HiHippie
Copy link
Contributor

@HiHippie HiHippie commented Mar 10, 2022

transforms.RandomGrayscale。

image

@HiHippie HiHippie mentioned this pull request Mar 10, 2022
13 tasks
@rentainhe
Copy link
Contributor

这咋只有一个pass哈哈哈哈,如果torchvision也是用Pillow实现的话,这里对齐应该不难

@HiHippie
Copy link
Contributor Author

这咋只有一个pass哈哈哈哈,如果torchvision也是用Pillow实现的话,这里对齐应该不难

我打算先把MOCOV3那边权重载一下再来搞这边,就先pass了一下2333

@HiHippie HiHippie changed the title New features needed: transforms.RandomGrayscale Add New features: transforms.RandomGrayscale Mar 10, 2022
@HiHippie HiHippie self-assigned this Mar 10, 2022
@rentainhe
Copy link
Contributor

这咋只有一个pass哈哈哈哈,如果torchvision也是用Pillow实现的话,这里对齐应该不难

我打算先把MOCOV3那边权重载一下再来搞这边,就先pass了一下2333

OK没问题,按你的节奏来

@rentainhe
Copy link
Contributor

这个PR可以今天推一下然后合并进去~

@rentainhe
Copy link
Contributor

和主分支的changelog还有冲突,merge main一下后fix一下冲突~

@HiHippie
Copy link
Contributor Author

和主分支的changelog还有冲突,merge main一下后fix一下冲突~

已解决

rentainhe
rentainhe previously approved these changes Mar 11, 2022
@@ -988,3 +988,28 @@ def rotate(
return F_t.rotate(
img, matrix=matrix, interpolation=interpolation.value, expand=expand, fill=fill
)


def rgb_to_grayscale(img: Tensor, num_output_channels: int = 1) -> Tensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

img: Tensor 是不是限定了输入的只能是flow.tensor,不能说PIL?

Copy link
Contributor

Choose a reason for hiding this comment

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

可能是对齐了torchvision的实现

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的,对齐torch实现的

Copy link
Contributor Author

Choose a reason for hiding this comment

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

对齐torch的实现:

    if not isinstance(img, flow.Tensor):
        return F_pil.to_grayscale(img, num_output_channels)

    return F_t.rgb_to_grayscale(img, num_output_channels)


def __init__(self, p=0.1):
super().__init__()
self.p = p
Copy link
Contributor

Choose a reason for hiding this comment

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

assert一下p的范围吧,p给2好像代码会运行

Copy link
Contributor

Choose a reason for hiding this comment

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

对,这里可以对p的范围进行监控

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

- if num_output_channels = 1 : returned image is single channel
- if num_output_channels = 3 : returned image is 3 channel with r = g = b
"""
if not isinstance(img, flow.Tensor):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

对齐torch,这里有处理非flow.tensor的代码

please, consider using meth:`~flowvision.transforms.functional.to_grayscale` with PIL Image.

Args:
img (PIL Image or Tensor): RGB Image to be converted to grayscale.
Copy link
Contributor

Choose a reason for hiding this comment

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

那这里就不是PIL,还要995行的if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是可以处理PIL Image的呀

@rentainhe rentainhe merged commit 177598f into main Mar 11, 2022
@rentainhe rentainhe deleted the Add_transforms.RandomGrayscale branch March 11, 2022 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants