Skip to content

Commit 40ae4ae

Browse files
Keras 3 compatibility (#2170)
* Tf generator changes (#2168) * Keras3 tests (#2152) * Update requirements for Keras 3 * Update Requirements * Update Requirements * Add randint for keras3 compatibility * remove force generator * fix few tests * fix tests * fix more tests * Update actions.yml * Tf generator changes (#2162) * Keras3 tests (#2152) * Update requirements for Keras 3 * Update Requirements * Update Requirements * Add randint for keras3 compatibility * remove force generator * fix few tests * fix tests * fix more tests * Revert "Replace `RandomGenerator` with `SeedGenerator` (#2150)" (#2161) This reverts commit 365a675. * Update actions.yml --------- Co-authored-by: Ramesh Sampath <[email protected]> * updates to rescaling * fix import * code reformat * namescope * update name_scope * correct ops.random * update base aug layer * code reformat * skip rand_augment test * disable random shear test * skip test * update import * fix format and base layer * ads smart resize * undo last commit * smart_resize update * update imports * correct shameful spelling mistake * update resizing * update resizing * update imports * disable ragged tensor test * skip tests * change back translation and zoom test * revert test changes * update * skip repeated augmentation tests * disable random shear test * code reformat * remove legacy_seed * code reformat * revert updates to tests * update tests * fix mock test --------- Co-authored-by: Ramesh Sampath <[email protected]> * Skip keras 3 incompatible layers (#2169) * Update requirements.txt * disable flaky test * code reformat * fixes tests on coco metric and serialization * code reformat * Skip test on RandAugment * Skip test on RandAugment --------- Co-authored-by: Ramesh Sampath <[email protected]>
1 parent e9b3d34 commit 40ae4ae

File tree

77 files changed

+404
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+404
-325
lines changed

.devcontainer/setup.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sudo pip install --upgrade pip
2+
sudo pip install -r requirements.txt --progress-bar off
23
sudo pip install -e ".[tests]"
34
sudo apt update
45
sudo apt install -y clang-format

.github/workflows/actions.yml

+13-17
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ permissions:
1111
contents: read
1212

1313
jobs:
14-
keras2:
15-
name: Test the code with tf.keras
14+
keras_2:
15+
name: Test the code with Keras 2
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1919
- name: Set up Python 3.9
20-
uses: actions/setup-python@v1
20+
uses: actions/setup-python@v4
2121
with:
2222
python-version: 3.9
2323
- name: Get pip cache dir
@@ -34,7 +34,7 @@ jobs:
3434
${{ runner.os }}-pip-
3535
- name: Install dependencies
3636
run: |
37-
pip install tensorflow>=2.13.0
37+
pip install tensorflow~=2.14
3838
pip install torch>=2.0.1+cpu
3939
pip install "jax[cpu]"
4040
pip install keras-core
@@ -44,17 +44,17 @@ jobs:
4444
TEST_CUSTOM_OPS: false
4545
run: |
4646
pytest keras_cv/ --ignore keras_cv/models/legacy/ --durations 0
47-
multibackend:
48-
name: Test the code with Keras Core
47+
keras_3:
48+
name: Test the code with Keras 3
4949
strategy:
5050
fail-fast: false
5151
matrix:
5252
backend: [tensorflow, jax, torch]
5353
runs-on: ubuntu-latest
5454
steps:
55-
- uses: actions/checkout@v2
55+
- uses: actions/checkout@v3
5656
- name: Set up Python 3.9
57-
uses: actions/setup-python@v1
57+
uses: actions/setup-python@v4
5858
with:
5959
python-version: 3.9
6060
- name: Get pip cache dir
@@ -71,11 +71,7 @@ jobs:
7171
${{ runner.os }}-pip-
7272
- name: Install dependencies
7373
run: |
74-
pip install tensorflow>=2.13.0
75-
pip install "jax[cpu]"
76-
pip install torch>=2.0.1+cpu
77-
pip install torchvision>=0.15.1
78-
pip install keras-core
74+
pip install -r requirements.txt
7975
pip install -e ".[tests]" --progress-bar off --upgrade
8076
- name: Test with pytest
8177
env:
@@ -99,9 +95,9 @@ jobs:
9995
name: Check the code format
10096
runs-on: ubuntu-latest
10197
steps:
102-
- uses: actions/checkout@v2
98+
- uses: actions/checkout@v3
10399
- name: Set up Python 3.9
104-
uses: actions/setup-python@v1
100+
uses: actions/setup-python@v4
105101
with:
106102
python-version: 3.9
107103
- name: Get pip cache dir
@@ -118,7 +114,7 @@ jobs:
118114
${{ runner.os }}-pip-
119115
- name: Install dependencies
120116
run: |
121-
pip install tensorflow>=2.13.0
117+
pip install tensorflow~=2.14
122118
pip install -e ".[tests]" --progress-bar off --upgrade
123119
- name: Lint
124120
run: bash shell/lint.sh

.github/workflows/devcontainer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
steps:
2121

2222
- name: Checkout (GitHub)
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v4
2424

2525
- name: Build and run dev container task
2626
uses: devcontainers/[email protected]

.github/workflows/nightly.yml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
pip install -r requirements.txt --progress-bar off
4141
- name: Build wheel file
4242
run: |
43+
export BUILD_WITH_CUSTOM_OPS=false
4344
python pip_build.py --nightly
4445
- name: Publish to PyPI
4546
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/release.yml

+33-100
Original file line numberDiff line numberDiff line change
@@ -8,105 +8,38 @@ permissions:
88
contents: read
99

1010
jobs:
11-
deploy-with-custom-ops:
12-
# This job is currently skipped until we cut a release with custom ops.
13-
if: false
14-
name: Build and deploy release wheels with custom ops
15-
runs-on: ${{ matrix.os }}
16-
strategy:
17-
matrix:
18-
# To switch on windows-2022/latest, please verify the bazel version:
19-
# https://github.com/bazelbuild/bazel/issues/14232#issuecomment-1011247429
20-
os: ['macos-12', 'windows-2019', 'ubuntu-18.04']
21-
py-version: ['3.9', '3.10', '3.11']
22-
tf-version: ['2.13.0']
23-
use-macos-arm: [false]
24-
include:
25-
- os: 'macos-12'
26-
tf-version: '2.13.0'
27-
py-version: '3.9'
28-
use-macos-arm: true
29-
- os: 'macos-12'
30-
tf-version: '2.13.0'
31-
py-version: '3.10'
32-
use-macos-arm: true
33-
fail-fast: false
34-
steps:
35-
- uses: actions/checkout@v2
36-
- name: Set up Python
37-
uses: actions/setup-python@v1
38-
with:
39-
python-version: ${{ matrix.py-version }}
40-
- name: Get pip cache dir
41-
id: pip-cache
42-
run: |
43-
python -m pip install --upgrade pip setuptools wheel auditwheel twine
44-
echo "::set-output name=dir::$(pip cache dir)"
45-
- name: pip cache
46-
uses: actions/cache@v2
47-
with:
48-
path: ${{ steps.pip-cache.outputs.dir }}
49-
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
50-
restore-keys: |
51-
${{ runner.os }}-pip-
52-
- name: Install dependencies
53-
run: |
54-
python -m pip install tensorflow-cpu==${{ matrix.tf-version }}
55-
python -m pip install -e ".[tests]" --progress-bar off --upgrade
56-
- name: Configure Build Environment
57-
run: |
58-
python build_deps/configure.py
59-
- name: Reinstall TensorFlow (MacOS ARM)
60-
if: ${{ matrix.os == 'macos-12' && matrix.use-macos-arm}}
61-
run: |
62-
python -m pip uninstall -y tensorflow-cpu
63-
python -m pip install --platform=macosx_12_0_arm64 --no-deps --target=$(python -c 'import site; print(site.getsitepackages()[0])') --upgrade tensorflow-macos==${{ matrix.tf-version }}
64-
- name: Bazel Build
65-
if: ${{ ! matrix.use-macos-arm }}
66-
run: |
67-
export BUILD_WITH_CUSTOM_OPS=true
68-
bazel build build_pip_pkg
69-
- name: Bazel Build (MacOS ARM)
70-
if: ${{ matrix.use-macos-arm}}
71-
run: |
72-
bazel build --cpu=darwin_arm64 --copt -mmacosx-version-min=12.0 --linkopt -mmacosx-version-min=12.0 build_pip_pkg
73-
- name: Build wheels
74-
run: |
75-
export BUILD_WITH_CUSTOM_OPS=true
76-
bazel-bin/build_pip_pkg wheels
77-
- name: Repair wheels (manylinux)
78-
if: ${{ matrix.os == 'ubuntu-18.04' }}
79-
run: |
80-
python -m pip install --upgrade patchelf==0.14
81-
bash build_deps/tf_auditwheel_patch.sh
82-
python -m auditwheel repair --plat manylinux2014_x86_64 wheels/*.whl
83-
rm wheels/*.whl
84-
mv wheelhouse/* wheels/
85-
- name: Upload wheels
86-
env:
87-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
88-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
89-
run: |
90-
twine upload wheels/*
91-
deploy-without-custom-ops:
92-
name: Build and deploy release wheels without custom ops
11+
run-test-for-release:
12+
uses: ./.github/workflows/actions.yml
13+
release:
14+
name: Build and publish to PyPI
9315
runs-on: ubuntu-latest
9416
steps:
95-
- uses: actions/checkout@v2
96-
- name: Set up Python
97-
uses: actions/setup-python@v1
98-
with:
99-
python-version: 3.9
100-
- name: Build wheels
101-
run: |
102-
pip install tensorflow==2.13.0
103-
python -m pip install --upgrade setuptools wheel twine
104-
python -m pip install --upgrade -r requirements.txt
105-
export BUILD_WITH_CUSTOM_OPS=false
106-
python pip_build.py
107-
- name: Upload wheels
108-
env:
109-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
110-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
111-
run: |
112-
twine upload dist/*.whl
17+
- uses: actions/checkout@v3
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: 3.9
22+
- name: Get pip cache dir
23+
id: pip-cache
24+
run: |
25+
python -m pip install --upgrade pip setuptools
26+
echo "::set-output name=dir::$(pip cache dir)"
27+
- name: pip cache
28+
uses: actions/cache@v2
29+
with:
30+
path: ${{ steps.pip-cache.outputs.dir }}
31+
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
32+
restore-keys: |
33+
${{ runner.os }}-pip-
34+
- name: Install dependencies
35+
run: |
36+
pip install -r requirements.txt --progress-bar off
37+
- name: Build a binary wheel and a source tarball
38+
run: |
39+
export BUILD_WITH_CUSTOM_OPS=false
40+
python pip_build.py
41+
- name: Publish distribution to PyPI
42+
if: startsWith(github.ref, 'refs/tags')
43+
uses: pypa/gh-action-pypi-publish@master
44+
with:
45+
password: ${{ secrets.PYPI_API_TOKEN }}

benchmarks/vectorized_jittered_resize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def test_consistency_with_old_impl(self):
259259
# makes offsets fixed to (0.5, 0.5)
260260
with unittest.mock.patch.object(
261261
layer._random_generator,
262-
"random_uniform",
262+
"uniform",
263263
return_value=tf.convert_to_tensor([[0.5, 0.5]]),
264264
):
265265
output = layer(image)

benchmarks/vectorized_mosaic.py

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def _batch_augment(self, inputs):
101101
minval=0,
102102
maxval=batch_size,
103103
dtype=tf.int32,
104-
seed=self._random_generator.make_legacy_seed(),
105104
)
106105
# concatenate the batches with permutation order to get all 4 images of
107106
# the mosaic

benchmarks/vectorized_random_brightness.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class OldRandomBrightness(BaseImageAugmentationLayer):
6161
"""
6262

6363
def __init__(self, factor, value_range=(0, 255), seed=None, **kwargs):
64-
super().__init__(seed=seed, force_generator=True, **kwargs)
64+
super().__init__(seed=seed, **kwargs)
6565
if isinstance(factor, float) or isinstance(factor, int):
6666
factor = (-factor, factor)
6767
self.factor = preprocessing_utils.parse_factor(

benchmarks/vectorized_random_contrast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class OldRandomContrast(BaseImageAugmentationLayer):
6060
"""
6161

6262
def __init__(self, factor, seed=None, **kwargs):
63-
super().__init__(seed=seed, force_generator=True, **kwargs)
63+
super().__init__(seed=seed, **kwargs)
6464
if isinstance(factor, (tuple, list)):
6565
min = 1 - factor[0]
6666
max = 1 + factor[1]

benchmarks/vectorized_random_crop.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def __init__(
5959
self, height, width, seed=None, bounding_box_format=None, **kwargs
6060
):
6161
super().__init__(
62-
**kwargs, autocast=False, seed=seed, force_generator=True
62+
**kwargs,
63+
autocast=False,
64+
seed=seed,
6365
)
6466
self.height = height
6567
self.width = width
@@ -72,7 +74,7 @@ def get_random_transformation(self, image=None, **kwargs):
7274
h_diff = image_shape[H_AXIS] - self.height
7375
w_diff = image_shape[W_AXIS] - self.width
7476
dtype = image_shape.dtype
75-
rands = self._random_generator.random_uniform([2], 0, dtype.max, dtype)
77+
rands = self._random_generator.uniform([2], 0, dtype.max, dtype)
7678
h_start = rands[0] % (h_diff + 1)
7779
w_start = rands[1] % (w_diff + 1)
7880
return {"top": h_start, "left": w_start}

benchmarks/vectorized_random_flip.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class OldRandomFlip(BaseImageAugmentationLayer):
7171
def __init__(
7272
self, mode=HORIZONTAL, seed=None, bounding_box_format=None, **kwargs
7373
):
74-
super().__init__(seed=seed, force_generator=True, **kwargs)
74+
super().__init__(seed=seed, **kwargs)
7575
self.mode = mode
7676
self.seed = seed
7777
if mode == HORIZONTAL:
@@ -101,13 +101,9 @@ def get_random_transformation(self, **kwargs):
101101
flip_horizontal = False
102102
flip_vertical = False
103103
if self.horizontal:
104-
flip_horizontal = (
105-
self._random_generator.random_uniform(shape=[]) > 0.5
106-
)
104+
flip_horizontal = self._random_generator.uniform(shape=[]) > 0.5
107105
if self.vertical:
108-
flip_vertical = (
109-
self._random_generator.random_uniform(shape=[]) > 0.5
110-
)
106+
flip_vertical = self._random_generator.uniform(shape=[]) > 0.5
111107
return {
112108
"flip_horizontal": tf.cast(flip_horizontal, dtype=tf.bool),
113109
"flip_vertical": tf.cast(flip_vertical, dtype=tf.bool),
@@ -237,13 +233,13 @@ def test_consistency_with_old_impl(self):
237233

238234
with unittest.mock.patch.object(
239235
layer._random_generator,
240-
"random_uniform",
236+
"uniform",
241237
return_value=tf.convert_to_tensor([[0.6]]),
242238
):
243239
output = layer(image)
244240
with unittest.mock.patch.object(
245241
old_layer._random_generator,
246-
"random_uniform",
242+
"uniform",
247243
return_value=tf.convert_to_tensor(0.6),
248244
):
249245
old_output = old_layer(image)

benchmarks/vectorized_random_rotation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(
9797
segmentation_classes=None,
9898
**kwargs,
9999
):
100-
super().__init__(seed=seed, force_generator=True, **kwargs)
100+
super().__init__(seed=seed, **kwargs)
101101
self.factor = factor
102102
if isinstance(factor, (tuple, list)):
103103
self.lower = factor[0]
@@ -122,7 +122,7 @@ def __init__(
122122
def get_random_transformation(self, **kwargs):
123123
min_angle = self.lower * 2.0 * np.pi
124124
max_angle = self.upper * 2.0 * np.pi
125-
angle = self._random_generator.random_uniform(
125+
angle = self._random_generator.uniform(
126126
shape=[1], minval=min_angle, maxval=max_angle
127127
)
128128
return {"angle": angle}

benchmarks/vectorized_random_translation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def __init__(
141141
fill_value=0.0,
142142
**kwargs,
143143
):
144-
super().__init__(seed=seed, force_generator=True, **kwargs)
144+
super().__init__(seed=seed, **kwargs)
145145
self.height_factor = height_factor
146146
if isinstance(height_factor, (tuple, list)):
147147
self.height_lower = height_factor[0]
@@ -217,13 +217,13 @@ def augment_image(self, image, transformation, **kwargs):
217217

218218
def get_random_transformation(self, image=None, **kwargs):
219219
batch_size = 1
220-
height_translation = self._random_generator.random_uniform(
220+
height_translation = self._random_generator.uniform(
221221
shape=[batch_size, 1],
222222
minval=self.height_lower,
223223
maxval=self.height_upper,
224224
dtype=tf.float32,
225225
)
226-
width_translation = self._random_generator.random_uniform(
226+
width_translation = self._random_generator.uniform(
227227
shape=[batch_size, 1],
228228
minval=self.width_lower,
229229
maxval=self.width_upper,

0 commit comments

Comments
 (0)