"git@developer.sourcefind.cn:change/sglang.git" did not exist on "99757cc3e68418f48713e69e5543a5783abcd84d"
Commit cefcb87b authored by Vishnu Banna's avatar Vishnu Banna
Browse files

address comments

parent 9474c108
......@@ -14,7 +14,6 @@
"""Detection Data parser and processing for YOLO."""
import tensorflow as tf
import numpy as np
from official.vision.beta.projects.yolo.ops import preprocessing_ops
from official.vision.beta.projects.yolo.ops import anchor
from official.vision.beta.ops import preprocess_ops
......@@ -230,7 +229,7 @@ class Parser(parser.Parser):
self._aug_rand_perspective)
# Clip and clean boxes.
boxes, inds = preprocessing_ops.apply_infos(
boxes, inds = preprocessing_ops.transform_and_clip_boxes(
boxes,
infos,
affine=affine,
......@@ -284,7 +283,7 @@ class Parser(parser.Parser):
# Clip and clean boxes.
image = image / 255.0
boxes, inds = preprocessing_ops.apply_infos(
boxes, inds = preprocessing_ops.transform_and_clip_boxes(
boxes, infos, shuffle_boxes=False, area_thresh=0.0, augment=True)
classes = tf.gather(classes, inds)
info = infos[-1]
......
......@@ -40,6 +40,7 @@ class Mosaic:
random_pad=False,
random_flip=False,
area_thresh=0.1,
pad_value=preprocessing_ops.PAD_VALUE,
seed=None):
"""Initializes parameters for mosaic.
......@@ -95,6 +96,7 @@ class Mosaic:
self._aug_rand_angle = aug_rand_angle
self._aug_rand_perspective = aug_rand_perspective
self._random_flip = random_flip
self._pad_value = pad_value
self._deterministic = seed != None
self._seed = seed if seed is not None else random.randint(0, 2**30)
......@@ -169,7 +171,7 @@ class Mosaic:
seed=self._seed)
# Clip and clean boxes.
boxes, inds = preprocessing_ops.apply_infos(
boxes, inds = preprocessing_ops.transform_and_clip_boxes(
boxes,
infos,
area_thresh=self._area_thresh,
......@@ -195,15 +197,15 @@ class Mosaic:
-center[1], center[1], seed=self._seed))
# clip the boxes to those with in the image
image = tfa.image.translate(
image, [cw, ch], fill_value=preprocessing_ops.get_pad_value())
image = tfa.image.translate(image, [cw, ch], fill_value=self._pad_value)
boxes = box_ops.denormalize_boxes(boxes, shape[:2])
boxes = boxes + tf.cast([ch, cw, ch, cw], boxes.dtype)
boxes = box_ops.clip_boxes(boxes, shape[:2])
inds = box_ops.get_non_empty_box_indices(boxes)
boxes = box_ops.normalize_boxes(boxes, shape[:2])
boxes, classes, is_crowd, area = self._select_ind(inds, boxes, classes, is_crowd, area)
boxes, classes, is_crowd, area = self._select_ind(
inds, boxes, classes, is_crowd, area)
# warp and scale the fully stitched sample
......@@ -220,7 +222,7 @@ class Mosaic:
image = tf.image.resize(image, (height, width))
# clip and clean boxes
boxes, inds = preprocessing_ops.apply_infos(
boxes, inds = preprocessing_ops.transform_and_clip_boxes(
boxes, None, affine=affine, area_thresh=self._area_thresh,
seed=self._seed)
classes, is_crowd, area = self._select_ind(inds, classes, is_crowd, area)
......
import tensorflow as tf
import numpy as np
import random
import os
import tensorflow_addons as tfa
from official.vision.beta.ops import box_ops as bbox_ops
......@@ -9,7 +8,6 @@ from official.vision.beta.ops import box_ops as bbox_ops
PAD_VALUE = 114
GLOBAL_SEED_SET = False
def set_random_seeds(seed=0):
"""Sets all accessible global seeds to properly apply randomization.
......@@ -24,18 +22,11 @@ def set_random_seeds(seed=0):
"""
if seed is not None:
global GLOBAL_SEED_SET
os.environ['PYTHONHASHSEED'] = str(seed)
random.seed(seed)
GLOBAL_SEED_SET = True
tf.random.set_seed(seed)
np.random.seed(seed)
def get_pad_value():
"""Return the padding value."""
return PAD_VALUE
def rand_uniform_strong(minval, maxval, dtype=tf.float32, seed=None, shape=[]):
"""A unified function for consistent random number generation.
......@@ -394,7 +385,8 @@ def resize_and_jitter_image(image,
# Letter box the image.
if letter_box == True or letter_box is None:
image_aspect_ratio, input_aspect_ratio = original_width / original_height, width / height
(image_aspect_ratio,
input_aspect_ratio) = original_width / original_height, width / height
distorted_aspect = image_aspect_ratio / input_aspect_ratio
delta_h, delta_w = 0.0, 0.0
......@@ -473,7 +465,7 @@ def resize_and_jitter_image(image,
# Pad the image to desired size.
image_ = tf.pad(
cropped_image, [[pad[0], pad[2]], [pad[1], pad[3]], [0, 0]],
constant_values=get_pad_value())
constant_values=PAD_VALUE)
pad_info = tf.stack([
tf.cast(tf.shape(cropped_image)[:2], tf.float32),
tf.cast(tf.shape(image_)[:2], dtype=tf.float32),
......@@ -660,7 +652,7 @@ def affine_warp_image(image,
image = tfa.image.transform(
image,
affine,
fill_value=get_pad_value(),
fill_value=PAD_VALUE,
output_shape=desired_size,
interpolation='bilinear')
......@@ -826,7 +818,7 @@ def resize_and_crop_boxes(boxes, image_scale, output_size, offset, box_history):
return clipped_boxes, box_history
def apply_infos(boxes,
def transform_and_clip_boxes(boxes,
infos,
affine=None,
shuffle_boxes=False,
......
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