-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
Signed-off-by: Onur Berk Tore <onurberk_t@hotmail.com>
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
@Dipet Hi!, 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). 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>
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>
@Dipet Hi!, |
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>
Hi @Dipet, However when I run it, the output is not related to my code.
|
Are you sure that you use correct environment? Try |
@Dipet, still same issue after checking the pip. |
Try |
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
@Dipet, |
@Dipet, |
|
||
def __init__( | ||
self, | ||
gravel_roi=(0.1, 0.4, 0.9, 0.9), |
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.
Please, add types.
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.
Added
@@ -765,6 +766,43 @@ def add_shadow(img, vertices_list): | |||
return image_rgb | |||
|
|||
|
|||
@ensure_contiguous | |||
@preserve_shape | |||
def add_gravel(img, gravels): |
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.
Please, add types.
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.
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)) |
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.
Better to use f-strings
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
|
||
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: |
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.
if no_of_patches < 1
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
self.no_of_patches = no_of_patches | ||
|
||
def generate_gravel_patch(self, rectangular_roi): | ||
x1 = rectangular_roi[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.
x1, y1, x2, y2 = rectangular_roi
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
for i in range((int)(area // 10)): | ||
x = np.random.randint(x1, x2) | ||
y = np.random.randint(y1, y2) | ||
gravels.append((x, y)) |
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.
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)
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
def __init__( | ||
self, | ||
gravel_roi=(0.1, 0.4, 0.9, 0.9), | ||
no_of_patches=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.
Strange name, better rename to number_of_patches
or count_of_patches
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
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))) |
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.
I can not understand logic of this rois
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.
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 |
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.
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]
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
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} |
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.
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)
}
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, thanks
Signed-off-by: delivers-26 <delivers-26@pop-os.localdomain>
Hi @Dipet, friendly ping. |
Signed-off-by: Onur Berk Tore onurberk_t@hotmail.com