-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1363 from Kaggle/upgrade-keras-3
Upgrade keras 3
- Loading branch information
Showing
5 changed files
with
107 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2021 Google LLC. | ||
# | ||
# 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. | ||
|
||
"""Access to Keras function with a different internal and external path.""" | ||
|
||
from tf_keras.src.engine import data_adapter as _data_adapter | ||
from tf_keras.src.models import Functional | ||
from tf_keras.layers import DenseFeatures | ||
from tf_keras.src.utils.dataset_creator import DatasetCreator | ||
|
||
|
||
unpack_x_y_sample_weight = _data_adapter.unpack_x_y_sample_weight | ||
get_data_handler = _data_adapter.get_data_handler |
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,23 @@ | ||
# Copyright 2021 Google LLC. | ||
# | ||
# 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 tensorflow as tf | ||
from tensorflow_decision_forests.keras import keras_internal | ||
|
||
|
||
# Does nothing. Ensures keras_internal can be loaded. | ||
|
||
if __name__ == "__main__": | ||
tf.test.main() | ||
|
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,41 @@ | ||
#!/bin/bash | ||
|
||
# The following "sed" are to patch the current version of tf-df with | ||
# a fix for keras 3. In essence, replaces the use of package name "tf.keras" with | ||
# "tf_keras" | ||
|
||
sed -i "/import tensorflow_decision_forests as tfdf/a import tf_keras" /opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/__init__.py && \ | ||
sed -i -e "/import tensorflow as tf/a import tf_keras" \ | ||
-e "/from yggdrasil_decision_forests.utils.distribute.implementations.grpc/a from tensorflow_decision_forests.keras import keras_internal" \ | ||
-e '/try:/{:a;N;/backend = tf.keras.backend/!ba;d}'\ | ||
/opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/keras/core.py && \ | ||
sed -i -e "s/from typing import Optional, List, Dict, Any, Union, NamedTuple/from typing import Any, Dict, List, NamedTuple, Optional, Union/g" \ | ||
-e "/import tensorflow as tf/a from tensorflow_decision_forests.keras import keras_internal" \ | ||
-e "/import tensorflow as tf/a import tf_keras" \ | ||
-e '/layers = tf.keras.layers/{:a;N;/backend = tf.keras.backend/!ba;d}' \ | ||
/opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/keras/core_inference.py && \ | ||
find /opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests -type f -exec sed -i \ | ||
-e "s/get_data_handler/keras_internal.get_data_handler/g" \ | ||
-e 's/"models.Functional"/keras_internal.Functional/g' \ | ||
-e "s/tf.keras.utils.unpack_x_y_sample_weight/keras_internal.unpack_x_y_sample_weight/g" \ | ||
-e "s/tf.keras.utils.experimental/keras_internal/g" \ | ||
{} \; && \ | ||
sed -i -e "/import tensorflow as tf/a import tf_keras" \ | ||
-e "/from tensorflow_decision_forests.keras import core/a from tensorflow_decision_forests.keras import keras_internal" \ | ||
-e '/layers = tf.keras.layers/{:a;N;/callbacks = tf.keras.callbacks/!ba;d}' \ | ||
/opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/keras/keras_test.py && \ | ||
find /opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/keras -type f -exec sed -i \ | ||
-e "s/ layers.Input/ tf_keras.layers.Input/g" \ | ||
-e "s/layers.minimum/tf_keras.layers.minimum/g" \ | ||
-e "s/layers.Concatenate/tf_keras.layers.Concatenate/g" \ | ||
-e "s/layers.Dense/tf_keras.layers.Dense/g" \ | ||
-e "s/layers.experimental.preprocessing./tf_keras.layers./g" \ | ||
-e "s/layers.DenseFeatures/keras_internal.layers.DenseFeatures/g" \ | ||
-e "s/models.Model/tf_keras.models.Model/g" {} \; && \ | ||
sed -i "s/ models.load_model/ tf_keras.models.load_model/g" /opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/keras/keras_test.py && \ | ||
sed -i "/import tensorflow as tf/a import tf_keras" /opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/keras/test_runner.py && \ | ||
sed -i "/import tensorflow as tf/a import tf_keras" /opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/keras/wrappers.py && \ | ||
sed -i -e "/import tensorflow as tf/a import tf_keras" \ | ||
-e "s/optimizer=optimizers.Adam()/optimizer=tf_keras.optimizers.Adam()/g" \ | ||
/opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests/keras/wrappers_pre_generated.py && \ | ||
find /opt/conda/lib/python3.10/site-packages/tensorflow_decision_forests -type f -exec sed -i "s/tf.keras./tf_keras./g" {} \; |
This file was deleted.
Oops, something went wrong.