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
Conversation
这咋只有一个pass哈哈哈哈,如果torchvision也是用Pillow实现的话,这里对齐应该不难 |
我打算先把MOCOV3那边权重载一下再来搞这边,就先pass了一下2333 |
OK没问题,按你的节奏来 |
这个PR可以今天推一下然后合并进去~ |
和主分支的changelog还有冲突,merge main一下后fix一下冲突~ |
已解决 |
@@ -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: |
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.
img: Tensor
是不是限定了输入的只能是flow.tensor,不能说PIL?
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.
可能是对齐了torchvision的实现
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.
是的,对齐torch实现的
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.
对齐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 |
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.
assert一下p的范围吧,p给2好像代码会运行
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.
对,这里可以对p的范围进行监控
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.
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): |
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.
对齐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. |
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.
那这里就不是PIL,还要995行的if
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.
是可以处理PIL Image的呀
transforms.RandomGrayscale。