Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a max line length of 80 universally #1552

Merged
merged 25 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7816a83
Enforces line length 80 Part 1
ID6109 Mar 18, 2023
f63d839
Enforces line length 80 Part 2 and fixes typos
ID6109 Mar 19, 2023
9529907
Enforces line length 80 Part 3 and fixes typos
ID6109 Mar 20, 2023
8b5f4bd
Enforces line length 80 Part 4 and fixes typos
ID6109 Mar 20, 2023
2ceb745
Merge branch 'master' of https://github.com/keras-team/keras-cv into …
ID6109 Mar 20, 2023
c3e4518
Enforces line length 80 Part 5 and fixes typos
ID6109 Mar 20, 2023
76b4164
Merge branch 'master' of https://github.com/keras-team/keras-cv into …
ID6109 Mar 20, 2023
d78fbe9
Minor change
ID6109 Mar 20, 2023
2bdeaf9
Merge branch 'master' of https://github.com/keras-team/keras-cv into …
ID6109 Mar 21, 2023
fae927e
Replaced double spaces with a single space
ID6109 Mar 21, 2023
a4646fc
Merge branch 'master' of https://github.com/keras-team/keras-cv into …
ID6109 Mar 21, 2023
fbbd972
Merge branch 'master' of https://github.com/keras-team/keras-cv into …
ID6109 Mar 21, 2023
7af3dfc
Merge Conflicts
ID6109 Mar 21, 2023
38b32f0
Minor Changes
ID6109 Mar 21, 2023
035cb6e
Merge branch 'master' of https://github.com/keras-team/keras-cv into …
ID6109 Mar 23, 2023
469fbe6
Resolves Merge Conflicts
ID6109 Mar 23, 2023
6193336
Merge branch 'master' into MaxLineLength
haifeng-jin Apr 4, 2023
92ab80f
Merge branch 'master' into MaxLineLength
haifeng-jin Apr 4, 2023
f662bfd
Merge conflicts
ID6109 Apr 5, 2023
356fb1a
Additional improvements + Changes requested
ID6109 Apr 5, 2023
53c8246
Merge branch 'master' of https://github.com/keras-team/keras-cv into …
ID6109 Apr 6, 2023
1e7477d
Merging
ID6109 Apr 6, 2023
80a6ed4
Changes requested
ID6109 Apr 7, 2023
0a40c56
Minor improvements
ID6109 Apr 7, 2023
06244d4
Merge branch 'master' into MaxLineLength
haifeng-jin Apr 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' of https://github.com/keras-team/keras-cv into …
…MaxLineLength

� Conflicts:
�	keras_cv/callbacks/waymo_evaluation_callback.py
�	keras_cv/layers/preprocessing/base_image_augmentation_layer.py
�	keras_cv/layers/preprocessing/cut_mix.py
�	keras_cv/layers/preprocessing/mosaic.py
�	keras_cv/models/object_detection/retina_net/retina_net_coco_test.py
  • Loading branch information
ID6109 committed Mar 21, 2023
commit fbbd97227a0171d2595fd966c878514b5cdedcf5
467 changes: 467 additions & 0 deletions benchmarks/vectorized_mosaic.py

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion examples/layers/preprocessing/bounding_box/demo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ def visualize_data(data, bounding_box_format):
def visualize_bounding_boxes(image, bounding_boxes, bounding_box_format):
color = np.array([[255.0, 0.0, 0.0]])
bounding_boxes = bounding_box.to_dense(bounding_boxes)
bounding_boxes = bounding_box.convert_format(
bounding_boxes,
source=bounding_box_format,
target="yxyx",
images=image,
)
if isinstance(image, tf.RaggedTensor):
image = image.to_tensor(0)
bounding_boxes = bounding_box.convert_format(
bounding_boxes,
source=bounding_box_format,
source="yxyx",
target="rel_yxyx",
images=image,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@


def main():
dataset = demo_utils.load_voc_dataset(bounding_box_format="rel_xyxy")
dataset = demo_utils.load_voc_dataset(bounding_box_format="xyxy")
random_shear = preprocessing.RandomShear(
x_factor=(0.1, 0.5),
y_factor=(0.1, 0.5),
bounding_box_format="rel_xyxy",
bounding_box_format="xyxy",
)
dataset = dataset.map(random_shear, num_parallel_calls=tf.data.AUTOTUNE)
demo_utils.visualize_data(dataset, bounding_box_format="rel_xyxy")
demo_utils.visualize_data(dataset, bounding_box_format="xyxy")


if __name__ == "__main__":
Expand Down
55 changes: 47 additions & 8 deletions keras_cv/callbacks/waymo_evaluation_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,29 @@ def point_clouds_only(point_clouds, target):
return point_clouds

def boxes_only(point_clouds, target):
return target["boxes"]

predicted_boxes, predicted_classes = self.model.predict(
dataset.map(point_clouds_only)
return target["3d_boxes"]

model_outputs = self.model.predict(dataset.map(point_clouds_only))[
"3d_boxes"
]

def flatten_target(boxes):
return tf.concat(
[
boxes["boxes"],
tf.expand_dims(
tf.cast(boxes["classes"], tf.float32), axis=-1
),
tf.expand_dims(
tf.cast(boxes["difficulty"], tf.float32), axis=-1
),
],
axis=-1,
)

gt_boxes = tf.concat(
[flatten_target(x) for x in iter(dataset.map(boxes_only))], axis=0
)
gt_boxes = tf.concat([x for x in iter(dataset.map(boxes_only))], axis=0)

boxes_per_gt_frame = gt_boxes.shape[1]
num_frames = gt_boxes.shape[0]
Expand All @@ -86,6 +103,12 @@ def boxes_only(point_clouds, target):
# padding)
gt_real_boxes = tf.not_equal(
gt_boxes[:, CENTER_XYZ_DXDYDZ_PHI.CLASS], -1
# Remove padded boxes
gt_real_boxes = tf.concat(
[x["mask"] for x in iter(dataset.map(boxes_only))], axis=0
)
gt_real_boxes = tf.reshape(
gt_real_boxes, (num_frames * boxes_per_gt_frame)
)
gt_boxes = tf.boolean_mask(gt_boxes, gt_real_boxes)

Expand All @@ -104,19 +127,24 @@ def boxes_only(point_clouds, target):
),
}

boxes_per_pred_frame = predicted_boxes.shape[1]
boxes_per_pred_frame = model_outputs["boxes"].shape[1]
total_predicted_boxes = boxes_per_pred_frame * num_frames
predicted_boxes = tf.reshape(
predicted_boxes, (total_predicted_boxes, 7)
model_outputs["boxes"], (total_predicted_boxes, 7)
)
predicted_classes = tf.reshape(
predicted_classes, (total_predicted_boxes, 2)
model_outputs["classes"], (total_predicted_boxes, 1)
)
# Remove boxes with class of -1 (these are non-boxes that come from
# padding)
prediction_scores = tf.reshape(
model_outputs["confidence"], (total_predicted_boxes, 1)
)
# Remove boxes with class of -1 (these are non-boxes that may come from padding)
pred_real_boxes = tf.reduce_all(predicted_classes != -1, axis=[-1])
predicted_boxes = tf.boolean_mask(predicted_boxes, pred_real_boxes)
predicted_classes = tf.boolean_mask(predicted_classes, pred_real_boxes)
prediction_scores = tf.boolean_mask(prediction_scores, pred_real_boxes)

predictions = {
"prediction_frame_id": tf.boolean_mask(
Expand All @@ -131,5 +159,16 @@ def boxes_only(point_clouds, target):
tf.zeros(predicted_boxes.shape[0]), tf.bool
),
}
predictions = {}

predictions["prediction_frame_id"] = tf.boolean_mask(
tf.repeat(frame_ids, boxes_per_pred_frame), pred_real_boxes
)
predictions["prediction_bbox"] = predicted_boxes
predictions["prediction_type"] = tf.squeeze(predicted_classes)
predictions["prediction_score"] = tf.squeeze(prediction_scores)
predictions["prediction_overlap_nlz"] = tf.cast(
tf.zeros(predicted_boxes.shape[0]), tf.bool
)

return ground_truth, predictions
30 changes: 25 additions & 5 deletions keras_cv/callbacks/waymo_evaluation_callback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
POINT_FEATURES = 3
NUM_POINTS = 20
NUM_BOXES = 2
BOX_FEATURES = 9
BOX_FEATURES = 7

METRIC_KEYS = [
"average_precision",
Expand Down Expand Up @@ -55,7 +55,18 @@ def test_model_fit(self):
(
points,
{
"boxes": boxes,
"3d_boxes": {
"boxes": boxes,
"classes": tf.ones((NUM_RECORDS, NUM_BOXES)),
"difficulty": tf.ones((NUM_RECORDS, NUM_BOXES)),
"mask": tf.concat(
[
tf.ones((NUM_RECORDS // 2, NUM_BOXES)),
tf.zeros((NUM_RECORDS // 2, NUM_BOXES)),
],
axis=0,
),
}
},
)
).batch(5)
Expand All @@ -68,9 +79,18 @@ def test_model_fit(self):
def build_model(self):
inputs = keras.Input(shape=(POINT_FEATURES, NUM_POINTS))
x = keras.layers.Flatten()(inputs)
x = keras.layers.Dense(BOX_FEATURES * NUM_BOXES)(x)
x = keras.layers.Reshape((NUM_BOXES, BOX_FEATURES))(x)
x = keras.layers.Lambda(lambda x: (x[:, :, :7], x[:, :, 7:]))(x)
# Add extra features for class and confidence
x = keras.layers.Dense(NUM_BOXES * (BOX_FEATURES + 2))(x)
x = keras.layers.Reshape((NUM_BOXES, BOX_FEATURES + 2))(x)
x = keras.layers.Lambda(
lambda x: {
"3d_boxes": {
"boxes": x[:, :, :7],
"classes": tf.cast(x[:, :, 7], tf.uint8),
"confidence": x[:, :, 8],
}
}
)(x)

class MeanLoss(keras.losses.Loss):
def call(self, y_true, y_pred):
Expand Down
5 changes: 2 additions & 3 deletions keras_cv/datasets/waymo/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os

import tensorflow as tf
import tensorflow_datasets as tfds

from keras_cv.datasets.waymo import transformer
from keras_cv.utils import assert_waymo_open_dataset_installed
Expand All @@ -28,9 +27,9 @@

def _generate_frames(segments, transformer):
def _generator():
for record in tfds.as_numpy(segments):
for record in segments:
frame = waymo_open_dataset.dataset_pb2.Frame()
frame.ParseFromString(record)
frame.ParseFromString(record.numpy())
yield transformer(frame)

return _generator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class BaseImageAugmentationLayer(keras.__internal__.layers.BaseRandomLayer):
the layer supports that.

`get_random_transformation()`, which should produce a random transformation
setting. The transformation object, which could be any type, will be passed
to `augment_image`, `augment_label` and `augment_bounding_boxes`, to
coordinate the randomness behavior, eg, in the RandomFlip layer, the image
and bounding_boxes should be changed in the same way.
setting. The transformation object, which could be of any type, will be
passed to `augment_image`, `augment_label` and `augment_bounding_boxes`, to
coordinate the randomness behaviour, e.g., in the RandomFlip layer, the
image and bounding_boxes should be changed in the same way.

The `call()` method supports two formats of inputs:
1. A single image tensor with shape (height, width, channels) or
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/preprocessing/cut_mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CutMix(BaseImageAugmentationLayer):
Args:
alpha: Float between 0 and 1. Inverse scale parameter for the gamma
distribution. This controls the shape of the distribution from which
the smoothing values are sampled. Defaults 1.0, which is a
the smoothing values are sampled. Defaults to 1.0, which is a
recommended value when training an imagenet1k classification model.
seed: Integer. Used to create a random seed.
References:
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.