@@ -460,35 +460,37 @@ def get_augmented_data(annotation_line, input_shape, augment=True, max_boxes=20,
460460 boxes = np .array ([list (map (float , box .split (',' )))
461461 for box in line_split [1 :]]).astype (int )
462462
463- if not augment :
464- # resize image
465- img_data , adj_box_data = normalize_image_bboxes (
466- image , boxes , input_shape , resize_img = resize_img ,
467- allow_rnd_shift = allow_rnd_shift , interp = interp )
468- box_data = _copy_bboxes (boxes , adj_box_data , max_boxes , check_dropped = False )
469- # yolo3.visual.show_augment_data(image_open(line_split[0]), boxes, img_data, box_data)
470- return img_data , box_data
463+ # if not augment:
464+ # img_data, adj_box_data = normalize_image_bboxes(
465+ # image, boxes, input_shape, resize_img=resize_img,
466+ # allow_rnd_shift=allow_rnd_shift, interp=interp)
467+ # box_data = _copy_bboxes(boxes, adj_box_data, max_boxes, check_dropped=False)
468+ # return img_data, box_data
471469
472470 # resize image
473471 # new_ar = cnn_w / cnn_h * _rand(1 - jitter, 1 + jitter) / _rand(1 - jitter, 1 + jitter)
474- scaling = _rand (1. / img_scaling , img_scaling )
475472 if resize_img :
473+ scaling = _rand (1. / img_scaling , img_scaling ) if augment else 1.
476474 img_data , scaling , (dx , dy ) = _scale_image_to_cnn (
477475 image , input_shape , scaling , allow_rnd_shift = allow_rnd_shift , interp = interp )
478476 else :
479477 img_data , scaling , (dx , dy ) = _crop_image_to_cnn (image , input_shape , allow_rnd_shift )
480478 image = Image .fromarray (np .round (img_data * 255 ).astype (np .uint8 ))
481479
482- # flip image or not
483- flip_horizontal = np .random .random () < 0.5 and flip_horizontal
484- if flip_horizontal :
485- image = image .transpose (Image .FLIP_LEFT_RIGHT )
486- flip_vertical = np .random .random () < 0.5 and flip_vertical
487- if flip_vertical :
488- image = image .transpose (Image .FLIP_TOP_BOTTOM )
489-
490- # distort image
491- img_data = augment_image_color (image , hue , sat , val )
480+ if augment :
481+ # flip image or not
482+ flip_horizontal = np .random .random () < 0.5 and flip_horizontal
483+ if flip_horizontal :
484+ image = image .transpose (Image .FLIP_LEFT_RIGHT )
485+ flip_vertical = np .random .random () < 0.5 and flip_vertical
486+ if flip_vertical :
487+ image = image .transpose (Image .FLIP_TOP_BOTTOM )
488+
489+ # distort image
490+ img_data = augment_image_color (image , hue , sat , val )
491+ else :
492+ flip_horizontal = False
493+ flip_vertical = False
492494
493495 if len (boxes ) == 0 :
494496 max_boxes = max_boxes if max_boxes else 1
@@ -499,7 +501,7 @@ def get_augmented_data(annotation_line, input_shape, augment=True, max_boxes=20,
499501 adj_box_data = adjust_bboxes (boxes , input_shape , flip_horizontal , flip_vertical ,
500502 scaling , scaling , dx , dy )
501503 box_data = _copy_bboxes (boxes , adj_box_data , max_boxes )
502- # yolo3.visual.show_augment_data(image_open(line_split[0]), boxes, img_data, box_data)
504+ # yolo3.visual.show_augment_data(image_open(line_split[0]), boxes, img_data, box_data, title=line_split[0] )
503505 return img_data , box_data
504506
505507
0 commit comments