-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[New API] add API paddle.vision.transforms.RandomErasing and paddle.vision.transforms.erase #42280
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
c58420a
to
dcfe74b
Compare
@@ -1297,6 +1298,144 @@ def _apply_image(self, img): | |||
self.center, self.fill) | |||
|
|||
|
|||
class RandomErasing(BaseTransform): | |||
"""Erase the pixels in a rectangle region selected randomly. This transform only | |||
supports 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.
Remove "This transform only supports 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.
Done,同时修改了class中其他文档的错误。
pil_img = Image.fromarray(np_img).convert('RGB') | ||
|
||
F.erase(np_img, 10, 10, 5, 5, 0, inplace=True) | ||
np.testing.assert_equal(np_img[12, 12, 0], 0) |
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.
需要测试所有值的正确性,而非一个值。
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.
Done.
np.testing.assert_equal(np_img[12, 12, 0], 0) | ||
|
||
pil_result = F.erase(pil_img, 10, 10, 5, 5, 0) | ||
np.testing.assert_equal(np.array(pil_result)[12, 12, 0], 0) |
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.
需要测试输入是paddle.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.
Done, 新增了Tensor类型输入的测试用例
else: | ||
value = self.value | ||
if value is not None and not (len(value) == 1 or | ||
len(value) == img.shape[-3]): |
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.shape[-3]是不是只是[c,h,w]的场景
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.
done
tensor_img = paddle.randn((3, 28, 28), dtype='float32') | ||
|
||
F.erase(np_img, 10, 10, 5, 5, 0, inplace=True) | ||
np.testing.assert_equal(np_img[10:15, 10:15, :], 0) |
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.
检查全图吧,检查局部并不完备
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.
done
b277046
to
bf0f8db
Compare
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.
LGTM.
Remember to add Chinese documents later.
25d2691
to
c5add50
Compare
a7cdd5c
to
596f7c1
Compare
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.
LG API
img_area = h * w | ||
log_ratio = np.log(ratio) | ||
for _ in range(10): | ||
erase_area = np.random.uniform(*scale) * img_area |
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.
这里不使用paddle原生api,而大量使用numpy的原因是什么?
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.
这个函数的作用在于确定erase函数执行时的参数数值,用numpy或者python原生数值处理主要有以下几个原因:
- 这里只需要数值/标量的结果即可,且不需要反向梯度。
- erase函数本身同时包含了numpy / paddle两种backends的实现。paddle api是针对Tensor进行处理,在numpy backends的函数中,需要额外引入一些Tensor和numpy/scalar的转化步骤。
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.
LGTM
PR types
New features
PR changes
APIs
Describe
Add new API
paddle.vision.transforms.RandomErasing
andpaddle.vision.transforms.erase
. These two APIs are used to erase pixels from a random selected area in given image.The DOC pr is : #4071