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

Enable to set random ranges to RandomEmojiOverlay parameters #177

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4829fd5
Add CI testing Github action
Jun 23, 2021
a734bb6
Merge pull request #1 from zpapakipos/ci_testing
zpapakipos Jun 23, 2021
dc3d173
Merge python & reqs steps
Jun 23, 2021
b61b90a
Merge pull request #2 from zpapakipos/ci_testing
zpapakipos Jun 23, 2021
0dd86be
Fix python step
Jun 23, 2021
b40e975
Use conda
Jun 23, 2021
e25a7f5
Fix spaces
Jun 23, 2021
536df14
Add conda init
Jun 23, 2021
0323503
Remove making new conda env
Jun 23, 2021
4b7cddb
Merge pull request #3 from zpapakipos/ci_testing
zpapakipos Jun 23, 2021
e3a1880
Merge branch 'facebookresearch:main' into main
zpapakipos Jun 25, 2021
76a1595
Merge branch 'facebookresearch:main' into main
zpapakipos Jun 29, 2021
ef8c2ad
Remove ci_testing workflow that I was testing
Jun 29, 2021
3782d69
Merge branch 'facebookresearch:main' into main
zpapakipos Jul 20, 2021
aeb2e42
Merge branch 'facebookresearch:main' into main
zpapakipos Aug 12, 2021
9eed988
Merge branch 'facebookresearch:main' into main
zpapakipos Sep 13, 2021
c7bbc85
Merge branch 'facebookresearch:main' into main
zpapakipos Oct 18, 2021
68d633a
Merge branch 'facebookresearch:main' into main
zpapakipos Nov 18, 2021
0ef2be2
Merge branch 'facebookresearch:main' into main
zpapakipos Nov 29, 2021
f465bfa
Merge branch 'facebookresearch:main' into main
zpapakipos Dec 1, 2021
e6ec59e
Merge branch 'facebookresearch:main' into main
zpapakipos Dec 17, 2021
6aba4ca
Merge branch 'facebookresearch:main' into main
zpapakipos Dec 17, 2021
eba52ac
Fix image tests by setting max pillow version
Jan 17, 2022
c0b3b7d
Enable to set random ranges to RandomEmojiOverlay parameters
Dec 16, 2021
7b7f678
determine parameters before getting metadata
Dec 16, 2021
72bf36e
Change test and expected metadata
Dec 16, 2021
5c95876
Sort args correctly
lyakaap Dec 18, 2021
27b6020
Give a useful error message if a bad tuple is given
lyakaap Dec 18, 2021
883bddc
Fix grammars in docs
lyakaap Dec 18, 2021
4da6514
Move seed description before metadata description
Dec 18, 2021
45659c2
Fix seed before testing RandomEmojiOverlay
Dec 18, 2021
a2d6994
Update test data regarding RandomEmojiOverlay
Dec 18, 2021
4a85b2b
Reflect review and apply black
Jan 4, 2022
7f059fb
Update augly/image/transforms.py
zpapakipos Jan 19, 2022
7083ee5
Revert changes in functional.py
Jan 25, 2022
8d35abd
Move seed setting / sampling
Jan 25, 2022
685ef2d
Rewrite docstring
Jan 25, 2022
15ee743
Merge branch 'feat/randomize-overlay' of github.com:lyakaap/AugLy int…
Jan 25, 2022
1f7fa72
Update augly/utils/expected_output/image_tests/expected_metadata.json
zpapakipos Jan 26, 2022
f5c75f1
Update augly/utils/expected_output/image_tests/expected_metadata.json
zpapakipos Jan 26, 2022
9b14126
Update augly/image/transforms.py
zpapakipos Jan 26, 2022
246226b
Update augly/image/transforms.py
zpapakipos Jan 26, 2022
6c636ff
Apply suggestions from code review
zpapakipos Jan 26, 2022
171b29e
Fix pyre & black errors
Jan 26, 2022
cfbf0be
Fix type errors
Jan 27, 2022
ae28176
Fix type error
Jan 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 42 additions & 9 deletions augly/image/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2326,21 +2326,28 @@ def __init__(
self,
emoji_directory: str = utils.SMILEY_EMOJI_DIR,
opacity: float = 1.0,
emoji_size: float = 0.15,
x_pos: float = 0.4,
y_pos: float = 0.4,
emoji_size: Union[float, Tuple[float, float]] = 0.15,
x_pos: Union[float, Tuple[float, float]] = 0.4,
y_pos: Union[float, Tuple[float, float]] = 0.8,
seed: Optional[int] = 42,
p: float = 1.0,
):
"""
@param emoji_directory: iopath directory uri containing the emoji images

@param opacity: the lower the opacity, the more transparent the overlaid emoji

@param emoji_size: size of the emoji is emoji_size * height of the original image
@param emoji_size: size of the emoji is emoji_size * height of the original image.
If set to a tuple, a position will randomly be chosen from the range provided
zpapakipos marked this conversation as resolved.
Show resolved Hide resolved

@param x_pos: position of emoji relative to the image width
@param x_pos: position of emoji relative to the image width.
If set to a tuple, a position will randomly be chosen from the range provided
zpapakipos marked this conversation as resolved.
Show resolved Hide resolved

@param y_pos: position of emoji relative to the image height
@param y_pos: position of emoji relative to the image height.
If set to a tuple, a position will randomly be chosen from the range provided
zpapakipos marked this conversation as resolved.
Show resolved Hide resolved

@param seed: if provided, this will set the random seed to ensure
consistency between runs
zpapakipos marked this conversation as resolved.
Show resolved Hide resolved

@param p: the probability of the transform being applied; default value is 1.0
"""
Expand All @@ -2351,6 +2358,7 @@ def __init__(
self.emoji_size = emoji_size
self.x_pos = x_pos
self.y_pos = y_pos
self.seed = seed

def apply_transform(
self,
Expand Down Expand Up @@ -2378,14 +2386,39 @@ def apply_transform(

@returns: Augmented PIL Image
"""
if self.seed is not None:
random.seed(self.seed)

if isinstance(self.emoji_size, tuple):
assert (
self.emoji_size[0] < self.emoji_size[1]
), "emoji_size must be a float or a tuple [low, high) to sample the value from"
emoji_size = random.uniform(self.emoji_size[0], self.emoji_size[1])
else:
emoji_size = self.emoji_size
if isinstance(self.x_pos, tuple):
assert (
self.x_pos[0] < self.x_pos[1]
), "x_pos must be a float or a tuple [low, high) to sample the value from"
x_pos = random.uniform(self.x_pos[0], self.x_pos[1])
else:
x_pos = self.x_pos
if isinstance(self.y_pos, tuple):
assert (
self.y_pos[0] < self.y_pos[1]
), "y_pos must be a float or a tuple [low, high) to sample the value from"
y_pos = random.uniform(self.y_pos[0], self.y_pos[1])
else:
y_pos = self.y_pos
zpapakipos marked this conversation as resolved.
Show resolved Hide resolved

emoji_path = random.choice(self.emoji_paths)
return F.overlay_emoji(
image,
emoji_path=os.path.join(self.emoji_directory, emoji_path),
opacity=self.opacity,
emoji_size=self.emoji_size,
x_pos=self.x_pos,
y_pos=self.y_pos,
emoji_size=emoji_size,
x_pos=x_pos,
y_pos=y_pos,
metadata=metadata,
bboxes=bboxes,
bbox_format=bbox_format,
Expand Down
5 changes: 4 additions & 1 deletion augly/tests/image_tests/transforms_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ def test_RandomBrightness(self):
@unittest.skip("Failing on some envs, will fix")
def test_RandomEmojiOverlay(self):
random.seed(1)
self.evaluate_class(imaugs.RandomEmojiOverlay(), fname="RandomEmojiOverlay")
self.evaluate_class(
imaugs.RandomEmojiOverlay(emoji_size=(0.15, 0.3)),
fname="RandomEmojiOverlay",
)

def test_RandomNoise(self):
self.evaluate_class(imaugs.RandomNoise(), fname="random_noise")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,17 +569,17 @@
"dst_bboxes": [[0.5, 0.5, 0.25, 0.75]],
"dst_height": 1080,
"dst_width": 1920,
"emoji_path": "twemojis/smileys/beating_heart.png",
"emoji_size": 0.15,
"intensity": 2.25,
"emoji_path": "twemojis/smileys/astonished_face.png",
"emoji_size": 0.24591401976868255,
"intensity": 6.047370511879199,
"name": "overlay_emoji",
"opacity": 1.0,
"output_path": null,
"src_bboxes": [[0.5, 0.5, 0.25, 0.75]],
"src_height": 1080,
"src_width": 1920,
"x_pos": 0.4,
"y_pos": 0.4
"y_pos": 0.8
}
],
"RandomPixelization": [
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
iopath>=0.1.8
nlpaug==1.1.3
numpy>=1.19.5
Pillow>=8.2.0
Pillow>=8.2.0,<9.0.0
python-magic>=0.4.22
regex>=2021.4.4
vidgear>=0.2.4