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

Add benchmarking script, update API_DESIGN.md to reflect the results. #161

Merged
merged 5 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 42 additions & 11 deletions .github/API_DESIGN.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
# API Design Guidelines
In general, KerasCV abides to the [API design guidelines of Keras](https://github.com/keras-team/governance/blob/master/keras_api_design_guidelines.md).
In general, KerasCV abides to the
[API design guidelines of Keras](https://github.com/keras-team/governance/blob/master/keras_api_design_guidelines.md).

There are a few API guidelines that apply only to KerasCV. These are discussed
in this document.

## Label Names
When working with `bounding_box` and `segmentation_map` labels the abbreviations `bbox` and
`segm` are often used. In KerasCV, we will *not* be using these abbreviations. This is done
to ensure full consistency in our naming convention. While the team is fond of the abbreviation
`bbox`, we are loss fond of `segm`. In order to ensure full consistency, we have decided to
# Label Names
When working with `bounding_box` and `segmentation_map` labels the
abbreviations `bbox` and `segm` are often used. In KerasCV, we will *not* be
using these abbreviations. This is done to ensure full consistency in our
naming convention. While the team is fond of the abbreviation `bbox`, we are
loss fond of `segm`. In order to ensure full consistency, we have decided to
use the full names for label types in our code base.

## Preprocessing Layers
### Color Based Preprocessing Layers
# Preprocessing Layers
## BaseImageAugmentationLayer
When implementing preprocessing, we encourage users to subclass the
`tf.keras.__internal__.layers.BaseImageAugmentationLayer`. This layer provides
a common `call()` method, auto vectorization, and more.

When subclassing `BaseImageAugmentationLayer`, several methods can overridden:

- `BaseImageAugmentationLayer.augment_image()` must be overridden
- `augment_label()` allows updates to be made to labels
- `augment_bounding_box()` allows updates to bounding boxes to be made

When a canonical layer subclassing BaseImageAugmentationLayer is available, a
link to it will be added here.

## Vectorization
`BaseImageAugmentationLayer` requires you to implement augmentations in an
image-wise basis instead of using a vectorized approach. This design choice
was based made on the results found in the
[vectorization\_strategy\_benchmark.py](../benchmarks/vectorization_strategy_benchmark.py)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How we are going to run this from command-line?

Copy link
Contributor

@bhack bhack Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this was not isolated as a performance test we need to tell to the devs to:

 pip install -e .

And the to pip uninstall keras-cv

benchmark.

In short, the benchmark shows that making use of `tf.vectorized_map()` performs
almost identically to a manually vectorized implementation. As such, we have
decided to rely on `tf.vectorized_map()` for performance.

![Results of vectorization strategy benchmark](images/runtime-plot.png)

## Color Based Preprocessing Layers
Some preprocessing layers in KerasCV perform color based transformations. This
includes `RandomBrightness`, `Equalize`, `Solarization`, and more. Preprocessing
layers that perform color based transformations make the following assumptions:
includes `RandomBrightness`, `Equalize`, `Solarization`, and more.
Preprocessing layers that perform color based transformations make the
following assumptions:

- these layers must accept a `value_range`, which is a tuple of numbers.
- `value_range` must default to `(0, 255)`
- input images may be of any `dtype`

Additionally, these preprocessing layers should cast back to the input images
original `dtype` before the end of their `call` body. This API design decision
is made to preserve simplicity and provide the easiest API to use.
is made to preserve simplicity and provide the easiest API to use.

The decision to support inputs of any `dtype` is made based on the nuance that
some Keras layers cast user inputs without the user knowing. For example, if
Expand Down
Binary file added .github/images/runtime-plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading