forked from AgentMaker/PaTTA
-
Notifications
You must be signed in to change notification settings - Fork 0
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
增加图像增强方式(HShift、VShift、Pad 等) #2
Merged
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9ede764
hg
Ainavo 32f7d58
1.01
Ainavo d2517e1
加了空格
Ainavo 8b20189
完善numpy转tensor
Ainavo bcbc291
1
Ainavo 89ba23a
pushle
Ainavo 534f953
6002bde
2d95e33
16b2df7
adjust code style
SigureMo b264b67
8f131a7
Merge branch 'edgnb' of https://github.com/cattidea/PaTTA into edgnb
Ainavo 6f5781e
export new transforms
SigureMo ee8d384
Merge branch 'edgnb' of https://github.com/cattidea/PaTTA into edgnb
Ainavo 302d5d4
测试颜色
Ainavo 9d1c079
add tests
SigureMo 62466ec
remove pad
SigureMo 6e530b1
docs
SigureMo 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 |
---|---|---|
|
@@ -263,3 +263,112 @@ def apply_deaug_mask(self, mask, **kwargs): | |
|
||
def apply_deaug_keypoints(self, keypoints, **kwargs): | ||
raise ValueError("`FiveCrop` augmentation is not suitable for keypoints!") | ||
|
||
|
||
class HorizontallyShift(DualTransform): | ||
"""Roll the x tensor along the given axis(axes=3). """ | ||
identity_param = 0 | ||
|
||
def __init__(self, shifts: List[float]): | ||
if self.identity_param not in shifts: | ||
shifts = [self.identity_param] + list(shifts) | ||
super().__init__("shifts", shifts) | ||
|
||
def apply_aug_image(self, image, shifts=0, **kwargs): | ||
image = F.hshift(image, shifts) | ||
return image | ||
|
||
def apply_deaug_mask(self, mask, shifts=0, **kwargs): | ||
return self.apply_aug_image(mask, -shifts) | ||
|
||
def apply_deaug_label(self, label, shifts=0, **kwargs): | ||
return label | ||
|
||
def apply_deaug_keypoints(self, keypoints, shifts=0, **kwargs): | ||
return F.keypoints_hshift(keypoints, -shifts) | ||
|
||
|
||
class VerticalShift(DualTransform): | ||
"""Roll the x tensor along the given axis(axes=2). """ | ||
identity_param = 0 | ||
|
||
def __init__(self, shifts: List[float]): | ||
if self.identity_param not in shifts: | ||
shifts = [self.identity_param] + list(shifts) | ||
super().__init__("shifts", shifts) | ||
|
||
def apply_aug_image(self, image, shifts=0, **kwargs): | ||
image = F.vshift(image, shifts) | ||
return image | ||
|
||
def apply_deaug_mask(self, mask, shifts=0, **kwargs): | ||
return self.apply_aug_image(mask, -shifts) | ||
|
||
def apply_deaug_label(self, label, shifts=0, **kwargs): | ||
return label | ||
|
||
def apply_deaug_keypoints(self, keypoints, shifts=0, **kwargs): | ||
return F.keypoints_vshift(keypoints, -shifts) | ||
|
||
|
||
|
||
class Pad(DualTransform): | ||
"""Pad the picture. """ | ||
identity_param = 0 | ||
def __init__( | ||
self, | ||
pads:List[Tuple[int, int]], | ||
mode:str, | ||
original_pad:Tuple[int, int] = None, | ||
value:int=0): | ||
if self.identity_param not in pads: | ||
pads = [self.identity_param] + list(pads) | ||
self.original_pad = original_pad, | ||
self.mode = mode, | ||
self.value = value, | ||
super().__init__("pads",pads) | ||
|
||
def apply_aug_image(self, image, pad=(0,0), **kwargs): | ||
image = F.pad(image, pad, self.mode, self.value) | ||
return image | ||
|
||
def apply_deaug_mask(self, mask, pad=(0,0), **kwargs): | ||
if self.original_pad is None: | ||
raise ValueError( | ||
"Provide original image size to make mask backward transformation" | ||
) | ||
if pad != self.original_pad: | ||
H = mask.shape[2] | ||
W = mask.shape[3] | ||
mask = mask[:,:,H-pad[0],W-pad[0]] | ||
return mask | ||
|
||
def apply_deaug_label(self, label, **kwargs): | ||
return label | ||
|
||
def apply_deaug_keypoints(self, keypoints, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO |
||
return F.keypoints_pad(keypoints,) | ||
|
||
|
||
class AdjustContrast(ImageOnlyTransform): | ||
'''''' | ||
SigureMo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
identity_param = 1 | ||
def __init__(self, factors: List[int]): | ||
if self.identity_param not in factors: | ||
factors = [self.identity_param] + list(factors) | ||
super.__init__("contrast_factor", factors) | ||
SigureMo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def apply_aug_image(self, image, factors=0.5, **kwargs): | ||
SigureMo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return F.adjust_contrast(image, factors) | ||
|
||
|
||
class AdjustBrightness(ImageOnlyTransform): | ||
'''''' | ||
identity_param = 1 | ||
SigureMo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def __init__(self, factors: List[int]): | ||
if self.identity_param not in factors: | ||
factors = [self.identity_param] + list(factors) | ||
super.__init__("brightness_factor", factors) | ||
SigureMo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def apply_aug_image(self, image, brightness_factor=0.5, **kwargs): | ||
SigureMo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return F.adjust_brightness(image, brightness_factor) | ||
|
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.
这里切片不对,应当是个范围,你这里只剩一个数了,而且为什么都是 pad[0] 呢?你先试着改一下,等会我再来看