Skip to content

Commit

Permalink
Merge branch 'master' into segformer_tf
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLandup0 committed Aug 18, 2023
2 parents c10963f + 5373b91 commit f882b3e
Show file tree
Hide file tree
Showing 179 changed files with 3,555 additions and 2,096 deletions.
44 changes: 44 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Bug
about: File a bug/issue
title: ''
labels: bug
assignees: ''

---

<!--
Note: Please search to see if an issue already exists for the bug you encountered.
-->

### Current Behavior:
<!-- A concise description of what you're experiencing. -->

### Expected Behavior:
<!-- A concise description of what you expected to happen. -->

### Steps To Reproduce:
<!--
Please include a minimal colab gist replicating the issue you encountered.
THIS IS CRITICAL FOR US TO HELP YOU. It is very difficult to fix an issue from a
stack trace alone.
To save a gist, choose "File > Save a copy as Github Gist" in colab. This
ensures that your colab is accessible to all users.
Exception: Any issues related to installation outside of colab or where
replication is not important to addressing your concern.
-->

### Version:
<!--
Example:
- HEAD
- 0.6.1
-->

### Anything else:
<!--
Links? References? Anything that will give us more context about the issue that
you are encountering!
-->
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
pip install tensorflow==2.13.0
python -m pip install --upgrade pip setuptools wheel twine
export BUILD_WITH_CUSTOM_OPS=false
python setup.py sdist bdist_wheel
python pip_build.py
- name: Upload wheels
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
34 changes: 34 additions & 0 deletions examples/layers/preprocessing/segmentation/aug_mix_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""aug_mix_demo.py shows how to use the AugMix preprocessing layer.
Uses the oxford iiit pet_dataset. In this script the pets
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import demo_utils
import tensorflow as tf

from keras_cv.layers import preprocessing


def main():
ds = demo_utils.load_oxford_iiit_pet_dataset()
augmix = preprocessing.AugMix([0, 255])
ds = ds.map(augmix, num_parallel_calls=tf.data.AUTOTUNE)
demo_utils.visualize_dataset(ds)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions examples/layers/preprocessing/segmentation/demo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
def normalize(input_image, input_mask):
input_image = tf.image.convert_image_dtype(input_image, tf.float32)
input_image = (input_image - mean) / tf.maximum(std, backend.epsilon())
input_image = input_image / 255
input_mask -= 1
return input_image, input_mask

Expand Down
34 changes: 34 additions & 0 deletions examples/layers/preprocessing/segmentation/fourier_mix_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""fourier_mix_demo.py shows how to use the FourierMix preprocessing layer.
Uses the oxford iiit pet_dataset. In this script the pets
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import demo_utils
import tensorflow as tf

from keras_cv.layers import preprocessing


def main():
ds = demo_utils.load_oxford_iiit_pet_dataset()
fouriermix = preprocessing.FourierMix(alpha=0.8)
ds = ds.map(fouriermix, num_parallel_calls=tf.data.AUTOTUNE)
demo_utils.visualize_dataset(ds)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_translation_demo.py shows how to use the RandomTranslation
preprocessing layer. Uses the oxford iiit pet_dataset. In this
script the pets are loaded, then are passed through the
preprocessing layers. Finally, they are shown using matplotlib.
"""
import demo_utils
import tensorflow as tf

from keras_cv.layers import preprocessing


def main():
ds = demo_utils.load_oxford_iiit_pet_dataset()
randomcutout = preprocessing.RandomTranslation(0.5, 0.5)
ds = ds.map(randomcutout, num_parallel_calls=tf.data.AUTOTUNE)
demo_utils.visualize_dataset(ds)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion examples/layers/preprocessing/segmentation/resize_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def load_data():
)
return ds.map(
lambda inputs: {
"images": tf.cast(inputs["image"], dtype=tf.float32) / 255.0,
"images": tf.cast(inputs["image"], dtype=tf.float32),
"segmentation_masks": inputs["segmentation_mask"] - 1,
}
)
Expand Down
2 changes: 1 addition & 1 deletion examples/visualization/plot_image_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Date created: 2022/10/16
Last modified: 2022/06/24
Description: Visualize ground truth and predicted bounding boxes for a given
dataset.
dataset.
"""

"""
Expand Down
49 changes: 49 additions & 0 deletions keras_cv/api_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import types

from keras_cv.backend import keras

try:
import namex
except ImportError:
namex = None


def maybe_register_serializable(symbol, package):
if isinstance(symbol, types.FunctionType) or hasattr(symbol, "get_config"):
keras.saving.register_keras_serializable(package=package)(symbol)


if namex:

class keras_cv_export(namex.export):
def __init__(self, path, package="keras_cv"):
super().__init__(package="keras_cv", path=path)
self.package = package

def __call__(self, symbol):
maybe_register_serializable(symbol, self.package)
return super().__call__(symbol)

else:

class keras_cv_export:
def __init__(self, path, package="keras_cv"):
self.package = package

def __call__(self, symbol):
maybe_register_serializable(symbol, self.package)
return symbol
2 changes: 2 additions & 0 deletions keras_cv/bounding_box/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import tensorflow as tf

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.backend import ops
from keras_cv.backend.scope import tf_data
Expand Down Expand Up @@ -298,6 +299,7 @@ def _xyxy_to_rel_yxyx(boxes, images=None, image_shape=None):
}


@keras_cv_export("keras_cv.bounding_box.convert_format")
@tf_data
def convert_format(
boxes, source, target, images=None, image_shape=None, dtype="float32"
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/bounding_box/ensure_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from keras_cv.api_export import keras_cv_export
from keras_cv.utils import preprocessing


@keras_cv_export("keras_cv.bounding_box.ensure_tensor")
def ensure_tensor(boxes, dtype=None):
boxes = boxes.copy()
for key in ["boxes", "classes", "confidence"]:
Expand Down
9 changes: 9 additions & 0 deletions keras_cv/bounding_box/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
formats.py contains axis information for each supported format.
"""

from keras_cv.api_export import keras_cv_export


@keras_cv_export("keras_cv.bounding_box.XYXY")
class XYXY:
"""XYXY contains axis indices for the XYXY format.
Expand All @@ -35,6 +38,7 @@ class XYXY:
BOTTOM = 3


@keras_cv_export("keras_cv.bounding_box.REL_XYXY")
class REL_XYXY:
"""REL_XYXY contains axis indices for the REL_XYXY format.
Expand All @@ -56,6 +60,7 @@ class REL_XYXY:
BOTTOM = 3


@keras_cv_export("keras_cv.bounding_box.CENTER_XYWH")
class CENTER_XYWH:
"""CENTER_XYWH contains axis indices for the CENTER_XYWH format.
Expand All @@ -75,6 +80,7 @@ class CENTER_XYWH:
HEIGHT = 3


@keras_cv_export("keras_cv.bounding_box.XYWH")
class XYWH:
"""XYWH contains axis indices for the XYWH format.
Expand All @@ -94,6 +100,7 @@ class XYWH:
HEIGHT = 3


@keras_cv_export("keras_cv.bounding_box.REL_XYWH")
class REL_XYWH:
"""REL_XYWH contains axis indices for the XYWH format.
Expand All @@ -113,6 +120,7 @@ class REL_XYWH:
HEIGHT = 3


@keras_cv_export("keras_cv.bounding_box.YXYX")
class YXYX:
"""YXYX contains axis indices for the YXYX format.
Expand All @@ -132,6 +140,7 @@ class YXYX:
RIGHT = 3


@keras_cv_export("keras_cv.bounding_box.REL_YXYX")
class REL_YXYX:
"""REL_YXYX contains axis indices for the REL_YXYX format.
Expand Down
3 changes: 3 additions & 0 deletions keras_cv/bounding_box/iou.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import math

from keras_cv import bounding_box
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.backend import ops

Expand Down Expand Up @@ -60,6 +61,7 @@ def _compute_intersection(boxes1, boxes2):
return intersect_height * intersect_width


@keras_cv_export("keras_cv.bounding_box.compute_iou")
def compute_iou(
boxes1,
boxes2,
Expand Down Expand Up @@ -170,6 +172,7 @@ def compute_iou(
return iou_lookup_table


@keras_cv_export("keras_cv.bounding_box.compute_ciou")
def compute_ciou(box1, box2, bounding_box_format, eps=1e-7):
"""
Computes the Complete IoU (CIoU) between two bounding boxes or between
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/bounding_box/mask_invalid_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
# limitations under the License.

from keras_cv import backend
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import ops
from keras_cv.bounding_box.to_ragged import to_ragged
from keras_cv.bounding_box.validate_format import validate_format


@keras_cv_export("keras_cv.bounding_box.mask_invalid_detections")
def mask_invalid_detections(bounding_boxes, output_ragged=False):
"""masks out invalid detections with -1s.
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/bounding_box/to_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import tensorflow as tf

import keras_cv.bounding_box.validate_format as validate_format
from keras_cv.api_export import keras_cv_export
from keras_cv.backend.scope import tf_data


Expand All @@ -36,6 +37,7 @@ def _classes_shape(batched, classes_shape, max_boxes):
return [max_boxes] + classes_shape[2:]


@keras_cv_export("keras_cv.bounding_box.to_dense")
@tf_data
def to_dense(bounding_boxes, max_boxes=None, default_value=-1):
"""to_dense converts bounding boxes to Dense tensors
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/bounding_box/to_ragged.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

import keras_cv.bounding_box.validate_format as validate_format
from keras_cv import backend
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras


@keras_cv_export("keras_cv.bounding_box.to_ragged")
def to_ragged(bounding_boxes, sentinel=-1, dtype=tf.float32):
"""converts a Dense padded bounding box `tf.Tensor` to a `tf.RaggedTensor`.
Expand Down
Loading

0 comments on commit f882b3e

Please sign in to comment.