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

Support for gravel augmentation #1365

Merged
merged 13 commits into from
Jan 31, 2023
Merged

Conversation

onurtore
Copy link
Contributor

Signed-off-by: Onur Berk Tore onurberk_t@hotmail.com

Signed-off-by: Onur Berk Tore  <onurberk_t@hotmail.com>
@onurtore onurtore changed the title Supports for gravel animations Supports for gravel augmentations Dec 15, 2022
@onurtore onurtore changed the title Supports for gravel augmentations Supports for gravel augmentation Dec 15, 2022
@onurtore onurtore marked this pull request as draft December 15, 2022 11:36
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
@onurtore
Copy link
Contributor Author

onurtore commented Dec 15, 2022

@Dipet Hi!,
There are some test in the test_serialization which are failing when I run pytest. However the functionality that I added (RandomGravel) not in the except_augmentations or augmentation_cls for these tests, so I do not understand why these tests testing this functionality.

Furthermore all of the failures are related to params are out of their limit (see below.) But I already checking them (in the transforms.py, RandomGravel class, I raise exceptions for them).

1

Clearly I lack the structure of the testing system, so any help would appreciated.

Edit: Turns out my implementation was wrong, not that I missunderstand the system.

Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
@onurtore
Copy link
Contributor Author

Okay, serialization tests are fixed, however the "test_additional_targets_for_image_only" still fails, any input is welcome.

Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
@onurtore onurtore marked this pull request as ready for review December 19, 2022 14:45
@onurtore
Copy link
Contributor Author

onurtore commented Dec 19, 2022

@Dipet Hi!,
Can you run the workflows please ?

Dipet and others added 6 commits December 21, 2022 18:49
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
@onurtore
Copy link
Contributor Author

Hi @Dipet,
How can I fix the documentation? Error output states to run: python3 tools/make_transforms_docs.py make

However when I run it, the output is not related to my code.

Traceback (most recent call last):
  File "tools/make_transforms_docs.py", line 194, in <module>
    main()
  File "tools/make_transforms_docs.py", line 174, in main
    transforms_info = get_transforms_info()
  File "tools/make_transforms_docs.py", line 80, in get_transforms_info
    if issubclass(cls, albumentations.DualIAATransform):
AttributeError: module 'albumentations' has no attribute 'DualIAATransform'

@Dipet
Copy link
Collaborator

Dipet commented Dec 22, 2022

Are you sure that you use correct environment? Try pip install -e . inside repo directory.

@onurtore
Copy link
Contributor Author

onurtore commented Dec 22, 2022

Are you sure that you use correct environment? Try pip install -e . inside repo directory.

@Dipet, still same issue after checking the pip.

@Dipet
Copy link
Collaborator

Dipet commented Dec 22, 2022

Try pip install imgaug

delivers-26 added 2 commits December 22, 2022 13:27
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
@onurtore
Copy link
Contributor Author

@Dipet,
Thanks, imgaug did the thing. All tests are now passed, you can review.

@onurtore
Copy link
Contributor Author

@Dipet,
Friendly ping.


def __init__(
self,
gravel_roi=(0.1, 0.4, 0.9, 0.9),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please, add types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@@ -765,6 +766,43 @@ def add_shadow(img, vertices_list):
return image_rgb


@ensure_contiguous
@preserve_shape
def add_gravel(img, gravels):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please, add types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

(gravel_lower_x, gravel_lower_y, gravel_upper_x, gravel_upper_y) = gravel_roi

if not 0 <= gravel_lower_x < gravel_upper_x <= 1 or not 0 <= gravel_lower_y < gravel_upper_y <= 1:
raise ValueError("Invalid gravel_roi. Got: {}".format(gravel_roi))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to use f-strings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


if not 0 <= gravel_lower_x < gravel_upper_x <= 1 or not 0 <= gravel_lower_y < gravel_upper_y <= 1:
raise ValueError("Invalid gravel_roi. Got: {}".format(gravel_roi))
if not 1 <= no_of_patches:
Copy link
Collaborator

Choose a reason for hiding this comment

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

if no_of_patches < 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

self.no_of_patches = no_of_patches

def generate_gravel_patch(self, rectangular_roi):
x1 = rectangular_roi[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

x1, y1, x2, y2 = rectangular_roi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 416 to 419
for i in range((int)(area // 10)):
x = np.random.randint(x1, x2)
y = np.random.randint(y1, y2)
gravels.append((x, y))
Copy link
Collaborator

Choose a reason for hiding this comment

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

count = area // 10
gravels = np.empty([count, 2], dtype=np.int64)
gravels[:, 0] = random_utils.randint(x1, x2, count)
gravels[:, 1] = random_utils.randint(y1, y2, count)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

def __init__(
self,
gravel_roi=(0.1, 0.4, 0.9, 0.9),
no_of_patches=2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Strange name, better rename to number_of_patches or count_of_patches

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 439 to 446
rectangular_rois = []
for i in range(self.no_of_patches):

xx1 = random_utils.randint(x_min + 1, x_max)
xx2 = random_utils.randint(x_min, xx1)
yy1 = random_utils.randint(y_min + 1, y_max)
yy2 = random_utils.randint(y_min, yy1)
rectangular_rois.append((xx2, yy2, min(xx1, xx2 + 200), min(yy1, yy2 + 30)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can not understand logic of this rois

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code and added comment for xmin, xmax, ymin, ymax. I think you understand that I am trying to generate xmin, xmax, ymin, ymax, so what part is not clear?

image_hls = cv2.cvtColor(img, cv2.COLOR_RGB2HLS)

for gravel in gravels:
minx, maxx, miny, maxy, val = gravel
Copy link
Collaborator

Choose a reason for hiding this comment

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

mixed up x and y, because gen formula is gravel_info = [max(y - r, 0), min(y + r, y), max(x - r, 0), min(x + r, x), r1]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 448 to 459
self.gravels_infos = []
for roi in rectangular_rois:
gravels = self.generate_gravel_patch(roi)
for gravel in gravels:
x = gravel[0]
y = gravel[1]
r = random_utils.randint(1, 4)
r1 = random_utils.randint(0, 255)
gravel_info = [max(y - r, 0), min(y + r, y), max(x - r, 0), min(x + r, x), r1]
self.gravels_infos.append(gravel_info)

return {"gravels_infos": self.gravels_infos}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Speedup:

minx = []
maxx = []
miny = []
maxy = []
val = []
for roi in rectangular_rois:
    gravels = self.generate_gravel_patch(roi)
    x = gravels[:, 0]
    y = gravels[:, 1]
    r = random_utils.randint(1, 4, len(gravels))
    r1 = random_utils.randint(0, 255, len(gravels))
    miny.append(np.maximum(y - r, 0))
    maxy.append(np.minimum(y + r, y))
    minx.append(np.maximum(x - r, 0))
    maxx.append(np.minimum(x + r, x))
    val.append(r1)

return {
    "gravels_infos": np.stack([
        np.concatenate(miny),
        np.concatenate(maxy),
        np.concatenate(minx),
        np.concatenate(maxx),
        np.concatenate(val),
    ], 1)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks

Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
@onurtore
Copy link
Contributor Author

Hi @Dipet, friendly ping.

@onurtore onurtore changed the title Supports for gravel augmentation Support for gravel augmentation Jan 29, 2023
@Dipet Dipet merged commit 7e49d47 into albumentations-team:master Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants