Commit c631af40 authored by Vishnu Banna's avatar Vishnu Banna
Browse files

datapipeline fixes

parent d5ae12e1
...@@ -147,6 +147,7 @@ class Parser(parser.Parser): ...@@ -147,6 +147,7 @@ class Parser(parser.Parser):
# Set the per level values needed for operation # Set the per level values needed for operation
self._darknet = darknet self._darknet = darknet
self._area_thresh = area_thresh self._area_thresh = area_thresh
self._level_limits = level_limits
self._seed = seed self._seed = seed
self._dtype = dtype self._dtype = dtype
...@@ -259,7 +260,7 @@ class Parser(parser.Parser): ...@@ -259,7 +260,7 @@ class Parser(parser.Parser):
self._aug_rand_saturation, self._aug_rand_saturation,
self._aug_rand_brightness, self._aug_rand_brightness,
seed=self._seed, seed=self._seed,
darknet=self._darknet) darknet=self._darknet or self._level_limits is not None)
# Cast the image to the selcted datatype. # Cast the image to the selcted datatype.
image, labels = self._build_label( image, labels = self._build_label(
...@@ -322,7 +323,7 @@ class Parser(parser.Parser): ...@@ -322,7 +323,7 @@ class Parser(parser.Parser):
imshape = image.get_shape().as_list() imshape = image.get_shape().as_list()
imshape[-1] = 3 imshape[-1] = 3
image.set_shape(imshape) image.set_shape(imshape)
labels = dict() labels = dict()
(labels['inds'], labels['upds'], (labels['inds'], labels['upds'],
labels['true_conf']) = self._label_builder(gt_boxes, gt_classes, width, labels['true_conf']) = self._label_builder(gt_boxes, gt_classes, width,
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
"""Mosaic op.""" """Mosaic op."""
import random import random
import tensorflow as tf import tensorflow as tf
import tensorflow_addons as tfa import tensorflow_addons as tfa
...@@ -22,7 +21,6 @@ from official.vision.beta.ops import box_ops ...@@ -22,7 +21,6 @@ from official.vision.beta.ops import box_ops
from official.vision.beta.ops import preprocess_ops from official.vision.beta.ops import preprocess_ops
from official.vision.beta.projects.yolo.ops import preprocessing_ops from official.vision.beta.projects.yolo.ops import preprocessing_ops
class Mosaic: class Mosaic:
"""Stitch together sets of 4 images to generate samples with more boxes.""" """Stitch together sets of 4 images to generate samples with more boxes."""
...@@ -211,6 +209,7 @@ class Mosaic: ...@@ -211,6 +209,7 @@ class Mosaic:
boxes, classes, is_crowd, area = self._select_ind(inds, boxes, classes, # pylint:disable=unbalanced-tuple-unpacking boxes, classes, is_crowd, area = self._select_ind(inds, boxes, classes, # pylint:disable=unbalanced-tuple-unpacking
is_crowd, area) is_crowd, area)
# warp and scale the fully stitched sample # warp and scale the fully stitched sample
image, _, affine = preprocessing_ops.affine_warp_image( image, _, affine = preprocessing_ops.affine_warp_image(
image, [self._output_size[0], self._output_size[1]], image, [self._output_size[0], self._output_size[1]],
...@@ -325,6 +324,11 @@ class Mosaic: ...@@ -325,6 +324,11 @@ class Mosaic:
else: else:
return self._add_param(noop) return self._add_param(noop)
def _beta(self, alpha, beta):
a = tf.random.gamma([], alpha)
b = tf.random.gamma([], beta)
return b / (a + b)
def _mixup(self, one, two): def _mixup(self, one, two):
"""Blend together 2 images for the mixup data augmentation.""" """Blend together 2 images for the mixup data augmentation."""
if self._mixup_frequency >= 1.0: if self._mixup_frequency >= 1.0:
...@@ -337,8 +341,8 @@ class Mosaic: ...@@ -337,8 +341,8 @@ class Mosaic:
if domo >= (1 - self._mixup_frequency): if domo >= (1 - self._mixup_frequency):
sample = one sample = one
otype = one['image'].dtype otype = one['image'].dtype
r = preprocessing_ops.random_uniform_strong(
0.4, 0.6, tf.float32, seed=self._seed) r = self._beta(8.0, 8.0)
sample['image'] = ( sample['image'] = (
r * tf.cast(one['image'], tf.float32) + r * tf.cast(one['image'], tf.float32) +
(1 - r) * tf.cast(two['image'], tf.float32)) (1 - r) * tf.cast(two['image'], tf.float32))
......
...@@ -170,14 +170,14 @@ def get_image_shape(image): ...@@ -170,14 +170,14 @@ def get_image_shape(image):
def _augment_hsv_darknet(image, rh, rs, rv, seed=None): def _augment_hsv_darknet(image, rh, rs, rv, seed=None):
"""Randomize the hue, saturation, and brightness via the darknet method.""" """Randomize the hue, saturation, and brightness via the darknet method."""
if rh > 0.0: if rh > 0.0:
delta = random_uniform_strong(-rh, rh, seed=seed) deltah = random_uniform_strong(-rh, rh, seed=seed)
image = tf.image.adjust_hue(image, delta) image = tf.image.adjust_hue(image, deltah)
if rs > 0.0: if rs > 0.0:
delta = random_scale(rs, seed=seed) deltas = random_scale(rs, seed=seed)
image = tf.image.adjust_saturation(image, delta) image = tf.image.adjust_saturation(image, deltas)
if rv > 0.0: if rv > 0.0:
delta = random_scale(rv, seed=seed) deltav = random_scale(rv, seed=seed)
image *= delta image *= tf.cast(deltav, image.dtype)
# clip the values of the image between 0.0 and 1.0 # clip the values of the image between 0.0 and 1.0
image = tf.clip_by_value(image, 0.0, 1.0) image = tf.clip_by_value(image, 0.0, 1.0)
...@@ -719,7 +719,7 @@ def affine_warp_boxes(affine, boxes, output_size, box_history): ...@@ -719,7 +719,7 @@ def affine_warp_boxes(affine, boxes, output_size, box_history):
return tf.stack([y_min, x_min, y_max, x_max], axis=-1) return tf.stack([y_min, x_min, y_max, x_max], axis=-1)
def _aug_boxes(affine_matrix, box): def _aug_boxes(affine_matrix, box):
"""Apply an affine transformation matrix M to the boxes augmente boxes.""" """Apply an affine transformation matrix M to the boxes augment boxes."""
corners = _get_corners(box) corners = _get_corners(box)
corners = tf.reshape(corners, [-1, 4, 2]) corners = tf.reshape(corners, [-1, 4, 2])
z = tf.expand_dims(tf.ones_like(corners[..., 1]), axis=-1) z = tf.expand_dims(tf.ones_like(corners[..., 1]), axis=-1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment