forked from keras-team/keras-cv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve keras 3 detection (keras-team#2132)
* improve keras 3 detection * update __init__ * update config * update config to update multibackend flag * updated spelling error * updatconfig * update tf_ops * update tf -ops * update tf ops * undo last commit * update tf_ops.py * reformat * update init() * update minor error in tf ops * remove check for keras 3 * revert changes to tf_ops * disable layers using internal base random layer * update syntax error * update imports in keras version check layer * update init method in keras version check * add seed argument * rasie error in class itself * update constructor * update to import directly from layers * update import in base image augmenattion layer * change import sin tf_ops * update tf ops import * change init * update tf_ops * update backend functions * keras.src * update namespace * update namescope correctly * code reformat * reformat and add backend functions * modified ops import * reformat * update ops * update backend * update ops * code reformatted * update import * update imports in ops * update error message * review changes added * update keras imports * update imports * update imports * update import in random.py * add issues link * code reformat * code reformat * review comments addressed * code reformat
- Loading branch information
1 parent
c10fd37
commit 43eefe7
Showing
10 changed files
with
206 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# 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 config | ||
|
||
_KERAS_CORE_ALIASES = { | ||
"utils->saving": [ | ||
"register_keras_serializable", | ||
"deserialize_keras_object", | ||
"serialize_keras_object", | ||
"get_registered_object", | ||
], | ||
"models->saving": ["load_model"], | ||
} | ||
|
||
if config.keras_3(): | ||
import keras # noqa: F403, F401 | ||
from keras import * # noqa: F403, F401 | ||
|
||
keras.backend.name_scope = keras.name_scope | ||
elif config.multi_backend(): | ||
import keras_core as keras # noqa: F403, F401 | ||
from keras_core import * # noqa: F403, F401 | ||
|
||
keras.backend.name_scope = keras.name_scope | ||
else: | ||
from tensorflow import keras # noqa: F403, F401 | ||
from tensorflow.keras import * # noqa: F403, F401 | ||
|
||
if not hasattr(keras, "saving"): | ||
keras.saving = types.SimpleNamespace() | ||
|
||
# add aliases | ||
for key, value in _KERAS_CORE_ALIASES.items(): | ||
src, _, dst = key.partition("->") | ||
src = src.split(".") | ||
dst = dst.split(".") | ||
|
||
src_mod, dst_mod = keras, keras | ||
|
||
# navigate to where we want to alias the attributes | ||
for mod in src: | ||
src_mod = getattr(src_mod, mod) | ||
for mod in dst: | ||
dst_mod = getattr(dst_mod, mod) | ||
|
||
# add an alias for each attribute | ||
for attr in value: | ||
if isinstance(attr, tuple): | ||
src_attr, dst_attr = attr | ||
else: | ||
src_attr, dst_attr = attr, attr | ||
attr_val = getattr(src_mod, src_attr) | ||
setattr(dst_mod, dst_attr, attr_val) | ||
|
||
# TF Keras doesn't have this rename. | ||
keras.activations.silu = keras.activations.swish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.