Skip to content

Commit

Permalink
fix dtype errors
Browse files Browse the repository at this point in the history
  • Loading branch information
divyashreepathihalli committed Nov 16, 2023
1 parent 73760b1 commit 75b4d30
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions benchmarks/vectorized_random_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ def get_random_transformation(self, image=None, **kwargs):
shape=[batch_size, 1],
minval=self.height_lower,
maxval=self.height_upper,
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)
width_translation = random.uniform(
shape=[batch_size, 1],
minval=self.width_lower,
maxval=self.width_upper,
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)
return {
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/vectorized_randomly_zoomed_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def get_random_transformation(
(),
minval=tf.minimum(0.0, original_height - new_height),
maxval=tf.maximum(0.0, original_height - new_height),
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)

width_offset = random.uniform(
(),
minval=tf.minimum(0.0, original_width - new_width),
maxval=tf.maximum(0.0, original_width - new_width),
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)

Expand Down
5 changes: 4 additions & 1 deletion keras_cv/backend/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

if keras_3():
from keras.random import * # noqa: F403, F401

# SeedGenerator is imported from `keras.random`
else:
from keras_core.random import * # noqa: F403, F401

class SeedGenerator:
def __init__(self, seed=None, **kwargs):
self._current_seed = [seed, 0]
Expand Down Expand Up @@ -86,7 +88,8 @@ def uniform(shape, minval=0.0, maxval=1.0, dtype=None, seed=None):
seed=make_seed(seed),
**kwargs,
)



def randint(shape, minval=0.0, maxval=1.0, dtype="int32", seed=None):
kwargs = {}
if dtype:
Expand Down
6 changes: 3 additions & 3 deletions keras_cv/layers/preprocessing/grid_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _compute_grid_mask(self, input_shape, ratio):
shape=(),
minval=tf.math.minimum(height * 0.5, width * 0.3),
maxval=tf.math.maximum(height * 0.5, width * 0.3) + 1,
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)
rectangle_side_len = tf.cast((ratio) * unit_size, tf.float32)
Expand All @@ -196,14 +196,14 @@ def _compute_grid_mask(self, input_shape, ratio):
shape=(),
minval=0.0,
maxval=unit_size,
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)
delta_y = random.uniform(
shape=(),
minval=0.0,
maxval=unit_size,
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)

Expand Down
13 changes: 6 additions & 7 deletions keras_cv/layers/preprocessing/mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501
BATCHED,
)
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import (
BOUNDING_BOXES,
)
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import (
IMAGES,
)
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import (
LABELS,
)
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import (
SEGMENTATION_MASKS,
)
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import (
VectorizedBaseImageAugmentationLayer,
)
from keras_cv.utils import preprocessing as preprocessing_utils
Expand Down Expand Up @@ -97,11 +97,10 @@ def __init__(

def get_random_transformation_batch(self, batch_size, **kwargs):
# pick 3 indices for every batch to create the mosaic output with.
permutation_order = random.uniform(
permutation_order = random.randint(
(batch_size, 3),
minval=0,
maxval=batch_size,
dtype=tf.int32,
seed=self._seed_generator,
)
# concatenate the batches with permutation order to get all 4 images of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _augment(self, inputs):
shape=(),
minval=0.0,
maxval=1.0,
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)
result = tf.cond(
Expand Down
3 changes: 1 addition & 2 deletions keras_cv/layers/preprocessing/random_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ def _batch_augment(self, inputs):
return super()._batch_augment(inputs)

def _augment(self, inputs, *args, **kwargs):
selected_op = random.uniform(
selected_op = random.randint(
(),
minval=0,
maxval=len(self.layers),
dtype=tf.int32,
seed=self._seed_generator,
)
# Warning:
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/layers/preprocessing/random_crop_and_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def get_random_transformation(
(),
minval=tf.minimum(0.0, 1.0 - new_height),
maxval=tf.maximum(0.0, 1.0 - new_height),
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)

width_offset = random.uniform(
(),
minval=tf.minimum(0.0, 1.0 - new_width),
maxval=tf.maximum(0.0, 1.0 - new_width),
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)

Expand Down
6 changes: 2 additions & 4 deletions keras_cv/layers/preprocessing/random_cutout.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,16 @@ def _compute_rectangle_position(self, inputs):
input_shape[0],
input_shape[1],
)
center_x = random.uniform(
center_x = random.randint(
[1],
0,
image_width,
dtype=tf.int32,
seed=self._seed_generator,
)
center_y = random.uniform(
center_y = random.randint(
[1],
0,
image_height,
dtype=tf.int32,
seed=self._seed_generator,
)
return center_x, center_y
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/preprocessing/random_hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_random_transformation_batch(self, batch_size, **kwargs):
(batch_size,),
0,
1,
tf.float32,
"float32",
seed=self._seed_generator,
)
invert = tf.where(
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/layers/preprocessing/random_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ def get_random_transformation_batch(self, batch_size, **kwargs):
shape=[batch_size, 1],
minval=self.height_lower,
maxval=self.height_upper,
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)
width_translations = random.uniform(
shape=[batch_size, 1],
minval=self.width_lower,
maxval=self.width_upper,
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)
return {
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/regularization/dropblock_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def call(self, x, training=None):

random_noise = random.uniform(
tf.shape(x),
dtype=tf.float32,
dtype="float32",
seed=self._seed_generator,
)
valid_block = tf.cast(valid_block, dtype=tf.float32)
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/utils/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def random_inversion(seed_generator):
def batch_random_inversion(seed_generator, batch_size):
"""Same as `random_inversion` but for batched inputs."""
negate = random.uniform(
(batch_size, 1), 0, 1, dtype=tf.float32, seed=seed_generator
(batch_size, 1), 0, 1, dtype="float32", seed=seed_generator
)
negate = tf.where(negate > 0.5, -1.0, 1.0)
return negate
Expand Down

0 comments on commit 75b4d30

Please sign in to comment.