Skip to content

Commit

Permalink
Vectorised crop and resize
Browse files Browse the repository at this point in the history
  • Loading branch information
soma2000-lang committed Feb 23, 2023
1 parent 587911a commit 7adadc2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion keras_cv/layers/preprocessing/random_crop_and_resize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The KerasCV Authors
# Copyright 2023 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,6 +101,7 @@ def get_random_transformation_batch(
new_heights = tf.clip_by_value(
tf.sqrt(crop_area_factor / aspect_ratio), 0.0, 1.0
) # to avoid unwanted/unintuitive effects

new_widths = tf.clip_by_value(
tf.sqrt(crop_area_factor * aspect_ratio), 0.0, 1.0
)
Expand Down Expand Up @@ -292,4 +293,12 @@ def get_config(self):

@classmethod
def from_config(cls, config):
if isinstance(config["crop_area_factor"], dict):
config["crop_area_factor"] = tf.keras.utils.deserialize_keras_object(
config["crop_area_factor"]
)
if isinstance(config["aspect_ratio_factor"], dict):
config["aspect_ratio_factor"] = tf.keras.utils.deserialize_keras_object(
config["aspect_ratio_factor"]
)
return cls(**config)

0 comments on commit 7adadc2

Please sign in to comment.