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

Keras import #2254

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions benchmarks/vectorization_strategy_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow.keras.layers as layers
from tensorflow import keras
from tensorflow.keras import backend

import keras_cv.backend.keras.layers as layers
from keras_cv.backend.keras import backend
from keras_cv.utils import bounding_box
from keras_cv.utils import fill_utils

Expand Down
3 changes: 2 additions & 1 deletion examples/layers/preprocessing/segmentation/demo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow_datasets as tfds
from tensorflow.keras import backend

from keras_cv.backend.keras import backend

image_size = 512
BATCH_SIZE = 32
Expand Down
8 changes: 4 additions & 4 deletions examples/training/contrastive/imagenet/simclr_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import tensorflow as tf
from absl import flags
from tensorflow import keras
from tensorflow.keras import callbacks
from tensorflow.keras import layers
from tensorflow.keras import metrics
from tensorflow.keras import optimizers

from keras_cv import losses
from keras_cv import models
from keras_cv import training
from keras_cv.backend.keras import callbacks
from keras_cv.backend.keras import layers
from keras_cv.backend.keras import metrics
from keras_cv.backend.keras import optimizers
from keras_cv.datasets import imagenet

flags.DEFINE_string(
Expand Down
3 changes: 2 additions & 1 deletion keras_cv/backend/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
keras.backend.name_scope = keras.name_scope
else:
from tensorflow import keras # noqa: F403, F401
from tensorflow.keras import * # noqa: F403, F401

from keras_cv.backend.keras import * # noqa: F403, F401

if not hasattr(keras, "saving"):
keras.saving = types.SimpleNamespace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import tensorflow.compat.v2 as tf
import tensorflow_datasets as tfds
from tensorflow import keras

from keras_cv import models
from keras_cv.backend import keras
from keras_cv.models.classification import image_classifier

# isort: off
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/callbacks/pycoco_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from tensorflow.keras.callbacks import Callback

from keras_cv import bounding_box
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.backend import ops
from keras_cv.metrics.coco import compute_pycoco_metrics
from keras_cv.models.object_detection.__internal__ import unpack_input
from keras_cv.utils.conditional_imports import assert_pycocotools_installed


@keras_cv_export("keras_cv.callbacks.PyCOCOCallback")
class PyCOCOCallback(Callback):
class PyCOCOCallback(keras.callbacks.Callback):
def __init__(
self, validation_data, bounding_box_format, cache=True, **kwargs
):
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/callbacks/waymo_evaluation_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import tensorflow as tf
from tensorflow.keras.callbacks import Callback

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.bounding_box_3d import CENTER_XYZ_DXDYDZ_PHI
from keras_cv.utils import assert_waymo_open_dataset_installed

Expand All @@ -30,7 +30,7 @@


@keras_cv_export("keras_cv.callbacks.WaymoEvaluationCallback")
class WaymoEvaluationCallback(Callback):
class WaymoEvaluationCallback(keras.callbacks.Callback):
def __init__(self, validation_data, config=None, **kwargs):
"""Creates a callback to evaluate Waymo Open Dataset (WOD) metrics on a
validation dataset.
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/callbacks/waymo_evaluation_callback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import numpy as np
import pytest
import tensorflow as tf
from tensorflow import keras

from keras_cv.backend import keras
from keras_cv.callbacks import WaymoEvaluationCallback
from keras_cv.tests.test_case import TestCase

Expand Down
2 changes: 1 addition & 1 deletion keras_cv/datasets/imagenet/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.

import tensorflow as tf
from tensorflow.keras import layers

from keras_cv.api_export import keras_cv_export
from keras_cv.backend.keras import layers


def parse_imagenet_example(img_size, crop_to_aspect_ratio):
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/datasets/pascal_voc/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class and instance segmentation masks.
import numpy as np
import tensorflow as tf
import tensorflow_datasets as tfds
from tensorflow import keras

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras

VOC_URL = "https://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar" # noqa: E501

Expand Down
1 change: 0 additions & 1 deletion keras_cv/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from tensorflow.keras.layers import CenterCrop
from tensorflow.keras.layers import RandomHeight
from tensorflow.keras.layers import RandomWidth

from keras_cv.layers.augmenter import Augmenter
from keras_cv.layers.feature_pyramid import FeaturePyramid
from keras_cv.layers.fusedmbconv import FusedMBConvBlock
Expand Down
3 changes: 1 addition & 2 deletions keras_cv/layers/feature_pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from tensorflow import keras

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras


@keras_cv_export("keras_cv.layers.FeaturePyramid")
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/feature_pyramid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import numpy as np
from tensorflow import keras

from keras_cv.backend import keras
from keras_cv.layers import FeaturePyramid
from keras_cv.tests.test_case import TestCase

Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/fusedmbconv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import pytest
import tensorflow as tf
from tensorflow import keras

from keras_cv.backend import keras
from keras_cv.layers.fusedmbconv import FusedMBConvBlock
from keras_cv.tests.test_case import TestCase

Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/mbconv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import pytest
import tensorflow as tf
from tensorflow import keras

from keras_cv.backend import keras
from keras_cv.layers.mbconv import MBConvBlock
from keras_cv.tests.test_case import TestCase

Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/object_detection/roi_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from typing import Tuple

import tensorflow as tf
from tensorflow import keras

from keras_cv import bounding_box
from keras_cv.backend import assert_tf_keras
from keras_cv.backend import keras


def _feature_bilinear_interpolation(
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/object_detection/roi_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from typing import Union

import tensorflow as tf
from tensorflow import keras

from keras_cv import bounding_box
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import assert_tf_keras
from keras_cv.backend import keras


@keras_cv_export("keras_cv.layers.ROIGenerator")
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/object_detection/roi_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# limitations under the License.

import tensorflow as tf
from tensorflow import keras

from keras_cv import bounding_box
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import assert_tf_keras
from keras_cv.backend import keras


@keras_cv_export("keras_cv.layers.ROIPooler")
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/object_detection/roi_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# limitations under the License.

import tensorflow as tf
from tensorflow import keras

from keras_cv import bounding_box
from keras_cv.backend import assert_tf_keras
from keras_cv.backend import keras
from keras_cv.bounding_box import iou
from keras_cv.layers.object_detection import box_matcher
from keras_cv.layers.object_detection import sampling
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/object_detection/rpn_label_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from typing import Mapping

import tensorflow as tf
from tensorflow import keras

from keras_cv import bounding_box
from keras_cv.backend import assert_tf_keras
from keras_cv.backend import keras
from keras_cv.bounding_box import iou
from keras_cv.layers.object_detection import box_matcher
from keras_cv.layers.object_detection import sampling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import numpy as np
import tensorflow as tf
from tensorflow import keras

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.backend import ops
from keras_cv.backend import scope
from keras_cv.backend.scope import tf_data
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/preprocessing/random_zoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


import tensorflow as tf
from tensorflow.keras import backend

from keras_cv.api_export import keras_cv_export
from keras_cv.backend.keras import backend
from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501
VectorizedBaseImageAugmentationLayer,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501

import numpy as np
from tensorflow import keras

from keras_cv.backend import keras
from keras_cv.layers.preprocessing_3d import base_augmentation_layer_3d
from keras_cv.layers.preprocessing_3d.waymo.frustum_random_point_feature_noise import ( # noqa: E501
FrustumRandomPointFeatureNoise,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501

import numpy as np
from tensorflow import keras

from keras_cv.backend import keras
from keras_cv.layers.preprocessing_3d import base_augmentation_layer_3d
from keras_cv.layers.preprocessing_3d.waymo.random_drop_box import RandomDropBox
from keras_cv.tests.test_case import TestCase
Expand Down
3 changes: 1 addition & 2 deletions keras_cv/layers/regularization/stochastic_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from tensorflow import keras

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras


@keras_cv_export("keras_cv.layers.StochasticDepth")
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/serialization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import inspect

from absl.testing import parameterized
from tensorflow import keras

from keras_cv import layers as cv_layers
from keras_cv.backend import keras
from keras_cv.backend.config import keras_3
from keras_cv.layers.vit_layers import PatchingAndEmbedding
from keras_cv.tests.test_case import TestCase
Expand Down
5 changes: 2 additions & 3 deletions keras_cv/layers/transformer_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from tensorflow import keras
from tensorflow.keras import layers

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.backend.keras import layers


@keras_cv_export("keras_cv.layers.TransformerEncoder")
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/layers/vit_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import math

import tensorflow as tf
from tensorflow.keras import layers

from keras_cv.api_export import keras_cv_export
from keras_cv.backend.keras import layers


@keras_cv_export("keras_cv.layers.PatchingAndEmbedding")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import numpy as np
import tensorflow as tf
from absl.testing import parameterized
from tensorflow import keras

from keras_cv.backend import keras
from keras_cv.backend import ops
from keras_cv.losses import FocalLoss
from keras_cv.tests.test_case import TestCase
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/metrics/object_detection/box_coco_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import numpy as np
import tensorflow as tf
import tensorflow.keras as keras

import keras_cv.backend.keras as keras
from keras_cv import bounding_box
from keras_cv.api_export import keras_cv_export
from keras_cv.backend import ops
Expand Down
4 changes: 2 additions & 2 deletions keras_cv/models/legacy/convmixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"""

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

from keras_cv.backend import keras
from keras_cv.backend.keras import layers
from keras_cv.models.legacy import utils
from keras_cv.models.legacy.weights import parse_weights

Expand Down
6 changes: 3 additions & 3 deletions keras_cv/models/legacy/convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"""

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import backend
from tensorflow.keras import layers

from keras_cv.backend import keras
from keras_cv.backend.keras import backend
from keras_cv.backend.keras import layers
from keras_cv.layers.regularization import StochasticDepth
from keras_cv.models.legacy import utils

Expand Down
4 changes: 2 additions & 2 deletions keras_cv/models/legacy/darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"""

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

from keras_cv.backend import keras
from keras_cv.backend.keras import layers
from keras_cv.models.backbones.csp_darknet.csp_darknet_utils import (
DarknetConvBlock,
)
Expand Down
Loading
Loading