Skip to content

Commit

Permalink
Merge branch 'master' into aritra/port-od-layers-keras3
Browse files Browse the repository at this point in the history
  • Loading branch information
ariG23498 committed Feb 27, 2024
2 parents aed3443 + 9207602 commit 4895e01
Show file tree
Hide file tree
Showing 28 changed files with 9,656 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ updates:
python:
patterns:
- "*"
ignore:
# TODO: ignore all updates for JAX GPU due to cuda version issue
- dependency-name: "jax[cuda12_pip]"
3 changes: 3 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
pip install torch>=2.0.1+cpu
pip install "jax[cpu]"
pip install keras-core
pip install keras-nlp-nightly --no-deps
pip install tensorflow-text==2.15
pip install -e ".[tests]" --progress-bar off --upgrade
- name: Test with pytest
env:
Expand Down Expand Up @@ -75,6 +77,7 @@ jobs:
run: |
pip install -r requirements.txt
pip install -e ".[tests]" --progress-bar off --upgrade
pip install keras-nlp-nightly
- name: Test with pytest
env:
TEST_CUSTOM_OPS: false # TODO(ianstenbit): test custom ops, or figure out what our story is here
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
uses: github/codeql-action/upload-sarif@e675ced7a7522a761fc9c8eb26682c8b27c42b2b # v3.24.1
with:
sarif_file: results.sarif
7 changes: 7 additions & 0 deletions .kokoro/github/ubuntu/gpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ nvcc --version

cd "src/github/keras-cv"
pip install -U pip setuptools
# psutil is used by background log reader
pip install -U psutil

if [ "${KERAS2:-0}" == "1" ]
then
Expand All @@ -29,21 +31,26 @@ then
pip install --extra-index-url https://download.pytorch.org/whl/cpu torch==2.1.0+cpu
pip install torchvision~=0.16.0
pip install "jax[cpu]"
pip install keras-nlp-nightly --no-deps
pip install tensorflow-text==2.15

elif [ "$KERAS_BACKEND" == "tensorflow" ]
then
echo "TensorFlow backend detected."
pip install -r requirements-tensorflow-cuda.txt --progress-bar off
pip install keras-nlp-nightly

elif [ "$KERAS_BACKEND" == "jax" ]
then
echo "JAX backend detected."
pip install -r requirements-jax-cuda.txt --progress-bar off
pip install keras-nlp-nightly

elif [ "$KERAS_BACKEND" == "torch" ]
then
echo "PyTorch backend detected."
pip install -r requirements-torch-cuda.txt --progress-bar off
pip install keras-nlp-nightly
fi

pip install --no-deps -e "." --progress-bar off
Expand Down
61 changes: 57 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Files: keras_cv/*

Copyright © 2023 The KerasCV Authors
All code in this repository excluding the code located in
keras_cv/layers/preprocessing_3d/waymo is licensed under the Apache License,
Expand Down Expand Up @@ -206,7 +208,58 @@ folder is licensed under terms appearing below.
See the License for the specific language governing permissions and
limitations under the License.

# The following applies only to the code appearing in
# keras_cv/layers/preprocessing_3d/waymo

License: https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE
---

Files: keras_cv/layers/preprocessing_3d/waymo/*

Copyright (c) 2023 Waymo LLC. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

Additional IP Rights Grant (Patents)
"Works" means the code located at keras_cv/layers/preprocessing_3d/waymo
licensed from Waymo LLC ("Waymo") for inclusion in the KerasCV project at
github.com/keras-team/keras-cv. “Patents" means the pending U.S. Patent App.
No. 63/418,259 and any issued patents arising therefrom. Subject to the terms
and conditions of this license, Waymo hereby grants to you a limited worldwide,
non-exclusive, royalty-free, personal patent license to make, have made, use,
and import the Works, where such license applies only to those Patent claims
that are necessarily infringed by the Works executing the ”preprocessing_3d”
augmentation library on 3D perception tasks using the
“lidaraugment_keraspolicy.py” file. This grant does not include claims that
would be infringed by combining the Works with other works, utilizing the Works
on other tasks, or as a consequence of further modification of the Works. If
you or your agent or exclusive licensee institute or order or agree to the
institution of patent litigation or any other patent enforcement activity
against any entity (including a cross-claim or counterclaim in a lawsuit)
alleging that the Works or any activity using the Works to execute functions for
3D perception tasks constitutes direct or contributory patent infringement, or
inducement of patent infringement, then any patent rights granted to you under
this license for the Works shall terminate as of the date such litigation is
filed.

DISCLAIMER

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 1 addition & 2 deletions keras_cv/conftest.py → conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import keras_core
import pytest
import tensorflow as tf
from packaging import version
Expand Down Expand Up @@ -101,7 +100,7 @@ def pytest_collection_modifyitems(config, items):
reason="This test is only supported on Keras 2",
)
skip_tf_only = pytest.mark.skipif(
keras_3() and keras_core.backend.backend() != "tensorflow",
keras_3() and backend_config.backend() != "tensorflow",
reason="This test is only supported on TensorFlow",
)
for item in items:
Expand Down
71 changes: 51 additions & 20 deletions keras_cv/custom_ops/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
licenses(["notice"]) # Apache 2.0

package(default_visibility = ["//visibility:public"])
package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)

config_setting(
name = "windows",
Expand All @@ -11,38 +12,68 @@ cc_library(
name = "box_util",
srcs = ["box_util.cc"],
hdrs = ["box_util.h"],
copts = select({
":windows": [
"/DEIGEN_STRONG_INLINE=inline",
"-DTENSORFLOW_MONOLITHIC_BUILD",
"/DPLATFORM_WINDOWS",
"/DEIGEN_HAS_C99_MATH",
"/DTENSORFLOW_USE_EIGEN_THREADPOOL",
"/DEIGEN_AVOID_STL_ARRAY",
"/Iexternal/gemmlowp",
"/wd4018",
"/wd4577",
"/DNOGDI",
"/UTF_COMPILE_LIBRARY",
],
"//conditions:default": [
"-pthread",
"-std=c++17",
],
}),
deps = [
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
],
copts = select({
":windows": ["/DEIGEN_STRONG_INLINE=inline", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", "/DTENSORFLOW_USE_EIGEN_THREADPOOL", "/DEIGEN_AVOID_STL_ARRAY", "/Iexternal/gemmlowp", "/wd4018", "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY"],
"//conditions:default": ["-pthread", "-std=c++17"],
}),
)

cc_binary(
name = '_keras_cv_custom_ops.so',
name = "_keras_cv_custom_ops.so",
srcs = [
"kernels/pairwise_iou_kernel.cc",
"ops/pairwise_iou_op.cc",
"kernels/withinbox_op.cc",
"ops/withinbox_op.cc",
"kernels/within_any_box_op.cc",
"kernels/withinbox_op.cc",
"ops/pairwise_iou_op.cc",
"ops/within_any_box_op.cc",
"ops/withinbox_op.cc",
],
copts = select({
":windows": [
"/DEIGEN_STRONG_INLINE=inline",
"-DTENSORFLOW_MONOLITHIC_BUILD",
"/DPLATFORM_WINDOWS",
"/DEIGEN_HAS_C99_MATH",
"/DTENSORFLOW_USE_EIGEN_THREADPOOL",
"/DEIGEN_AVOID_STL_ARRAY",
"/Iexternal/gemmlowp",
"/wd4018",
"/wd4577",
"/DNOGDI",
"/UTF_COMPILE_LIBRARY",
],
"//conditions:default": [
"-pthread",
"-std=c++17",
],
}),
features = select({
":windows": ["windows_export_all_symbols"],
"//conditions:default": [],
}),
linkshared = 1,
deps = [
":box_util",
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
":box_util",
],
features = select({
":windows": ["windows_export_all_symbols"],
"//conditions:default": [],
}),
copts = select({
":windows": ["/DEIGEN_STRONG_INLINE=inline", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", "/DTENSORFLOW_USE_EIGEN_THREADPOOL", "/DEIGEN_AVOID_STL_ARRAY", "/Iexternal/gemmlowp", "/wd4018", "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY"],
"//conditions:default": ["-pthread", "-std=c++17"],
}),
)
23 changes: 13 additions & 10 deletions keras_cv/layers/object_detection/roi_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ def _pool_single_sample(self, args):
feature_map: [H, W, C] float Tensor
rois: [N, 4] float Tensor
Returns:
pooled_feature_map: [target_size, C] float Tensor
pooled_feature_map: [N, target_height, target_width, C] float Tensor
"""
feature_map, rois = args
num_rois = ops.shape(rois)[0]
height, width, channel = ops.shape(feature_map)
num_rois = rois.get_shape().as_list()[0]
height, width, channel = feature_map.get_shape().as_list()
regions = []
# TODO (consider vectorize it for better performance)
for n in range(num_rois):
# [4]
Expand All @@ -125,7 +126,7 @@ def _pool_single_sample(self, args):
region_width = width * (roi[3] - roi[1])
h_step = region_height / self.target_height
w_step = region_width / self.target_width
regions = []
region_steps = []
for i in range(self.target_height):
for j in range(self.target_width):
height_start = y_start + i * h_step
Expand All @@ -145,16 +146,18 @@ def _pool_single_sample(self, args):
1, width_end - width_start
)
# [h_step, w_step, C]
region = feature_map[
region_step = feature_map[
height_start:height_end, width_start:width_end, :
]
# target_height * target_width * [C]
regions.append(ops.max(region, axis=[0, 1]))
regions = ops.reshape(
ops.stack(regions),
[self.target_height, self.target_width, channel],
region_steps.append(ops.max(region_step, axis=[0, 1]))
regions.append(
ops.reshape(
ops.stack(region_steps),
[self.target_height, self.target_width, channel],
)
)
return regions
return ops.stack(regions)

def get_config(self):
config = {
Expand Down
Loading

0 comments on commit 4895e01

Please sign in to comment.