@@ -133,12 +133,33 @@ def create_mosaic(images, netblock, target_dim, images_annotations=None, jitter=
133
133
134
134
# Jittering image beforehand
135
135
jitter_embedding = (pleft , pright , ptop , pbot )
136
- jittered_img = jitter_image_precalc (img , jitter_embedding , target_dim , annotations = annotations , image_info = image_info )
137
136
138
- # Do rest of the augmentations
139
- aug_image = augment_image (jittered_img , netblock , target_dim , annotations = annotations , image_info = image_info , jitter = False )
140
-
141
- place_image_mosaic (mosaic_img , aug_image , image_info , cut_x , cut_y , i , annotations = annotations )
137
+ try :
138
+ jittered_img = jitter_image_precalc (img , jitter_embedding , target_dim , annotations = annotations , image_info = image_info )
139
+ except :
140
+ print ("Error with jittering image inside create_mosaic:" )
141
+ print ("jitter_embedding:" , jitter_embedding )
142
+ raise
143
+
144
+ try :
145
+ # Do rest of the augmentations
146
+ aug_image = augment_image (jittered_img , netblock , target_dim , annotations = annotations , image_info = image_info , jitter = False )
147
+ except :
148
+ print ("Mosaic image index:" , i )
149
+ raise
150
+
151
+ try :
152
+ # Place the image on the mosaic
153
+ place_image_mosaic (mosaic_img , aug_image , image_info , cut_x , cut_y , i , annotations = annotations )
154
+ except :
155
+ print ("Error with placing mosaic image:" )
156
+ print ("placement image shape:" , mosaic_img .shape )
157
+ print ("aug image shape:" , aug_image .shape )
158
+ print ("jitter_embedding:" , jitter_embedding )
159
+ print ("cut_x:" , cut_x )
160
+ print ("cut_y:" , cut_y )
161
+ print ("image num:" , i )
162
+ raise
142
163
143
164
# Combining all annotations together into one tensor
144
165
if (images_annotations is not None ):
@@ -217,8 +238,6 @@ def place_image_mosaic(placement_image, image, image_info, cut_x, cut_y, i_num,
217
238
embed_w_fix = abs (avail_w - avail_w_fix )
218
239
embed_h_fix = abs (avail_h - avail_h_fix )
219
240
220
- # print(offset_x_fix, offset_y_fix, actual_w, actual_h, avail_w_fix, avail_h_fix)
221
-
222
241
pleft = pleft_fix
223
242
avail_w = avail_w_fix
224
243
ptop = ptop_fix
@@ -250,6 +269,7 @@ def place_image_mosaic(placement_image, image, image_info, cut_x, cut_y, i_num,
250
269
pleft = pleft
251
270
ptop = ptop
252
271
272
+ # Placing the mosaic
253
273
placement_image [placem_y1 :placem_y2 , placem_x1 :placem_x2 ] = image [ptop :pbot , pleft :pright ]
254
274
255
275
# Mapping annotations
@@ -383,7 +403,15 @@ def jitter_image(image, jitter, resize_coef, target_dim, annotations=None, image
383
403
oh = image .shape [CV2_H_DIM ]
384
404
385
405
precalc = get_jitter_embedding (ow , oh , jitter , resize_coef )
386
- jitter_img = jitter_image_precalc (image , precalc , target_dim , annotations = annotations , image_info = image_info )
406
+
407
+ try :
408
+ jitter_img = jitter_image_precalc (image , precalc , target_dim , annotations = annotations , image_info = image_info )
409
+ except :
410
+ print ("Error with jittering image:" )
411
+ print ("ow:" , ow )
412
+ print ("oh:" , oh )
413
+ print ("jitter precalc:" , precalc )
414
+ raise
387
415
388
416
return jitter_img
389
417
@@ -432,7 +460,7 @@ def jitter_image_precalc(image, precalc, target_dim, annotations=None, image_inf
432
460
dst_w_norm = 1.0
433
461
dst_h_norm = 1.0
434
462
else :
435
- # Just how darknet does it, it sort of reflects the dimension placement
463
+ # Negation to guarantee placement lines up on the destination image
436
464
dst_x1 = max (0 , - pleft )
437
465
dst_y1 = max (0 , - ptop )
438
466
dst_x2 = dst_x1 + crop_w
@@ -457,10 +485,11 @@ def jitter_image_precalc(image, precalc, target_dim, annotations=None, image_inf
457
485
new_img = image_resize (new_img , new_dim )
458
486
459
487
# Needed by image info and annotations
460
- start_x = round (dst_x1_norm * target_dim )
461
- start_y = round (dst_y1_norm * target_dim )
462
- embed_w = round (dst_w_norm * target_dim )
463
- embed_h = round (dst_h_norm * target_dim )
488
+ # Will take the floor to ensure we never go outside the image bounds
489
+ start_x = int (dst_x1_norm * target_dim )
490
+ start_y = int (dst_y1_norm * target_dim )
491
+ embed_w = int (dst_w_norm * target_dim )
492
+ embed_h = int (dst_h_norm * target_dim )
464
493
465
494
# Setting annotations
466
495
if (annotations is not None ):
@@ -543,7 +572,13 @@ def hsv_shift_image(image, hue, saturation, exposure, image_info=None):
543
572
"""
544
573
545
574
precalc = get_hsv_shifting (hue , saturation , exposure )
546
- new_img = hsv_shift_image_precalc (image , precalc , image_info = image_info )
575
+
576
+ try :
577
+ new_img = hsv_shift_image_precalc (image , precalc , image_info = image_info )
578
+ except :
579
+ print ("Error with HSV shifting:" )
580
+ print ("HSV precalc:" , precalc )
581
+ raise
547
582
548
583
return new_img
549
584
@@ -653,7 +688,7 @@ def flip_image(image, annotations=None, image_info=None):
653
688
654
689
# image_info
655
690
if (image_info is not None ):
656
- half_ow = round ( image .shape [CV2_W_DIM ] / 2.0 )
691
+ half_ow = image .shape [CV2_W_DIM ] / 2.0
657
692
pleft = image_info .aug_pleft
658
693
embed_w = image_info .aug_embed_w
659
694
@@ -663,7 +698,7 @@ def flip_image(image, annotations=None, image_info=None):
663
698
pleft += half_ow
664
699
pleft -= embed_w
665
700
666
- image_info .aug_pleft = pleft
701
+ image_info .aug_pleft = int ( pleft )
667
702
image_info .set_augmentation (new_img )
668
703
669
704
0 commit comments