Skip to content

Commit

Permalink
Switch to programmatic API generation with Namex
Browse files Browse the repository at this point in the history
  • Loading branch information
ianstenbit committed Jul 31, 2023
1 parent cc45f77 commit f041b97
Show file tree
Hide file tree
Showing 136 changed files with 340 additions and 146 deletions.
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
6 changes: 4 additions & 2 deletions keras_cv/bounding_box/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
"""Utility functions for working with bounding boxes."""

from keras_cv import bounding_box
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import ops
from keras_cv.bounding_box.formats import XYWH


@keras_cv_export("keras_cv.bounding_box.is_relative")
def is_relative(bounding_box_format):
"""A util to check if a bounding box format uses relative coordinates"""
if (
Expand All @@ -34,6 +36,7 @@ def is_relative(bounding_box_format):
return bounding_box_format.startswith("rel")


@keras_cv_export("keras_cv.bounding_box.as_relative")
def as_relative(bounding_box_format):
"""A util to get the relative equivalent of a provided bounding box format.
Expand Down Expand Up @@ -61,8 +64,7 @@ def _relative_area(boxes, bounding_box_format):
)


# bounding_boxes is a dictionary with shape:
# {"boxes": [None, None, 4], "mask": [None, None]}
@keras_cv_export("keras_cv.bounding_box.clip_to_image")
def clip_to_image(
bounding_boxes, bounding_box_format, images=None, image_shape=None
):
Expand Down
3 changes: 3 additions & 0 deletions keras_cv/bounding_box/validate_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
# limitations under the License.
import tensorflow as tf

from keras_cv.api_export import keras_cv_export


@keras_cv_export("keras_cv.bounding_box.validate_format")
def validate_format(bounding_boxes, variable_name="bounding_boxes"):
"""validates that a given set of bounding boxes complies with KerasCV
format.
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/callbacks/pycoco_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
from keras.callbacks import Callback

from keras_cv import bounding_box
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import ops
from keras_cv.metrics.coco import compute_pycoco_metrics
from keras_cv.models.object_detection.__internal__ import unpack_input
from keras_cv.utils.conditional_imports import assert_pycocotools_installed


@keras_cv_export("keras_cv.callbacks.PyCOCOCallback")
class PyCOCOCallback(Callback):
def __init__(
self, validation_data, bounding_box_format, cache=True, **kwargs
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/callbacks/waymo_evaluation_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
except ImportError:
WODDetectionEvaluator = None

from keras_cv.api_export import keras_cv_export
from keras_cv.bounding_box_3d import CENTER_XYZ_DXDYDZ_PHI


@keras_cv_export("keras_cv.callbacks.WaymoEvaluationCallback")
class WaymoEvaluationCallback(Callback):
def __init__(self, validation_data, config=None, **kwargs):
"""Creates a callback to evaluate Waymo Open Dataset (WOD) metrics on a
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/core/factor_sampler/constant_factor_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.

import tensorflow as tf
from tensorflow import keras

from keras_cv.api_export import keras_cv_export
from keras_cv.core.factor_sampler.factor_sampler import FactorSampler


@keras.utils.register_keras_serializable(package="keras_cv")
@keras_cv_export("keras_cv.core.ConstantFactorSampler")
class ConstantFactorSampler(FactorSampler):
"""ConstantFactorSampler samples the same factor for every call to
`__call__()`.
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/core/factor_sampler/factor_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from tensorflow import keras
from keras_cv.api_export import keras_cv_export


@keras.utils.register_keras_serializable(package="keras_cv")
@keras_cv_export("keras_cv.core.FactorSampler")
class FactorSampler:
"""FactorSampler represents a strength factor for use in an augmentation
layer.
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/core/factor_sampler/normal_factor_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.

import tensorflow as tf
from tensorflow import keras

from keras_cv.api_export import keras_cv_export
from keras_cv.core.factor_sampler.factor_sampler import FactorSampler


@keras.utils.register_keras_serializable(package="keras_cv")
@keras_cv_export("keras_cv.core.NormalFactorSampler")
class NormalFactorSampler(FactorSampler):
"""NormalFactorSampler samples factors from a normal distribution.
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/core/factor_sampler/uniform_factor_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.

import tensorflow as tf
from tensorflow import keras

from keras_cv.api_export import keras_cv_export
from keras_cv.core.factor_sampler.factor_sampler import FactorSampler


@keras.utils.register_keras_serializable(package="keras_cv")
@keras_cv_export("keras_cv.core.UniformFactorSampler")
class UniformFactorSampler(FactorSampler):
"""UniformFactorSampler samples factors uniformly from a range.
Expand Down
3 changes: 3 additions & 0 deletions keras_cv/datasets/imagenet/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import tensorflow as tf
from tensorflow.keras import layers

from keras_cv.api_export import keras_cv_export


def parse_imagenet_example(img_size, crop_to_aspect_ratio):
"""Function to parse a TFRecord example into an image and label"""
Expand Down Expand Up @@ -54,6 +56,7 @@ def apply(example):
return apply


@keras_cv_export("keras_cv.datasets.imagenet.load")
def load(
split,
tfrecord_path,
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/datasets/pascal_voc/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import tensorflow_datasets as tfds

from keras_cv import bounding_box
from keras_cv.api_export import keras_cv_export


def curry_map_function(bounding_box_format):
Expand All @@ -40,6 +41,7 @@ def apply(inputs):
return apply


@keras_cv_export("keras_cv.datasets.pascal_voc.load")
def load(
split,
bounding_box_format,
Expand Down
3 changes: 3 additions & 0 deletions keras_cv/datasets/pascal_voc/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class and instance segmentation masks.
import tensorflow_datasets as tfds
from tensorflow import keras

from keras_cv.api_export import keras_cv_export

VOC_URL = "https://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar" # noqa: E501

"""
Expand Down Expand Up @@ -463,6 +465,7 @@ def md_gen():
return dataset


@keras_cv_export("keras_cv.datasets.pascal_voc.segmentation.load")
def load(
split="sbd_train",
data_dir=None,
Expand Down
3 changes: 3 additions & 0 deletions keras_cv/datasets/waymo/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
except ImportError:
waymo_open_dataset = None

from keras_cv.api_export import keras_cv_export


def _generate_frames(segments, transformer):
def _generator():
Expand All @@ -35,6 +37,7 @@ def _generator():
return _generator


@keras_cv_export("keras_cv.datasets.waymo.load")
def load(
tfrecord_path,
transformer=transformer.build_tensors_from_wod_frame,
Expand Down
6 changes: 6 additions & 0 deletions keras_cv/datasets/waymo/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import numpy as np
import tensorflow as tf

from keras_cv.api_export import keras_cv_export
from keras_cv.utils import assert_waymo_open_dataset_installed

try:
Expand Down Expand Up @@ -609,6 +610,7 @@ def _box_3d_global_to_vehicle(
return tf.concat([new_center, dim, new_heading[..., tf.newaxis]], axis=-1)


@keras_cv_export("keras_cv.datasets.waymo.build_tensors_from_wod_frame")
def build_tensors_from_wod_frame(frame) -> Dict[str, tf.Tensor]:
"""Builds tensors from a Waymo Open Dataset frame.
Expand Down Expand Up @@ -673,6 +675,7 @@ def build_tensors_from_wod_frame(frame) -> Dict[str, tf.Tensor]:
}


@keras_cv_export("keras_cv.datasets.waymo.pad_or_trim_tensors")
def pad_or_trim_tensors(
frame: Dict[str, tf.Tensor], max_num_point=199600, max_num_label_box=1000
) -> Dict[str, tf.Tensor]:
Expand Down Expand Up @@ -720,6 +723,7 @@ def _pad_fn(t: tf.Tensor, max_counts: int) -> tf.Tensor:
return frame


@keras_cv_export("keras_cv.datasets.waymo.transform_to_vehicle_frame")
def transform_to_vehicle_frame(
frame: Dict[str, tf.Tensor]
) -> Dict[str, tf.Tensor]:
Expand Down Expand Up @@ -772,6 +776,7 @@ def _transform_to_vehicle_frame(
return frame


@keras_cv_export("keras_cv.datasets.waymo.convert_to_center_pillar_inputs")
def convert_to_center_pillar_inputs(
frame: Dict[str, tf.Tensor]
) -> Dict[str, Any]:
Expand Down Expand Up @@ -802,6 +807,7 @@ def convert_to_center_pillar_inputs(
return y


@keras_cv_export("keras_cv.datasets.waymo.build_tensors_for_augmentation")
def build_tensors_for_augmentation(
frame: Dict[str, tf.Tensor]
) -> Tuple[tf.Tensor, tf.Tensor]:
Expand Down
Loading

0 comments on commit f041b97

Please sign in to comment.