Convert Keras Core to Keras 3.
This commit is contained in:
parent
10d0349a75
commit
b9be76a13a
22
README.md
22
README.md
@ -1,9 +1,9 @@
|
||||
[![](https://github.com/keras-team/keras-core/workflows/Tests/badge.svg?branch=main)](https://github.com/keras-team/keras-core/actions?query=workflow%3ATests+branch%3Amain)
|
||||
[![](https://badge.fury.io/py/keras-core.svg)](https://badge.fury.io/py/keras-core)
|
||||
[![](https://github.com/keras-team/keras/workflows/Tests/badge.svg?branch=main)](https://github.com/keras-team/keras/actions?query=workflow%3ATests+branch%3Amain)
|
||||
[![](https://badge.fury.io/py/keras.svg)](https://badge.fury.io/py/keras)
|
||||
|
||||
# Keras Core: A new multi-backend Keras
|
||||
# Keras 3: A new multi-backend Keras
|
||||
|
||||
Keras Core is a new multi-backend implementation of the Keras API, with support for TensorFlow, JAX, and PyTorch.
|
||||
Keras 3 is a new multi-backend implementation of the Keras API, with support for TensorFlow, JAX, and PyTorch.
|
||||
|
||||
**WARNING:** At this time, this package is experimental.
|
||||
It has rough edges and not everything might work as expected.
|
||||
@ -13,7 +13,7 @@ Once ready, this package will become Keras 3.0 and subsume `tf.keras`.
|
||||
|
||||
## Local installation
|
||||
|
||||
Keras Core is compatible with Linux and MacOS systems. To install a local development version:
|
||||
Keras 3 is compatible with Linux and MacOS systems. To install a local development version:
|
||||
|
||||
1. Install dependencies:
|
||||
|
||||
@ -28,7 +28,7 @@ python pip_build.py --install
|
||||
```
|
||||
|
||||
You should also install your backend of choice: `tensorflow`, `jax`, or `torch`.
|
||||
Note that `tensorflow` is required for using certain Keras Core features: certain preprocessing layers as
|
||||
Note that `tensorflow` is required for using certain Keras 3 features: certain preprocessing layers as
|
||||
well as `tf.data` pipelines.
|
||||
|
||||
## Configuring your backend
|
||||
@ -46,16 +46,16 @@ In Colab, you can do:
|
||||
import os
|
||||
os.environ["KERAS_BACKEND"] = "jax"
|
||||
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
```
|
||||
|
||||
**Note:** The backend must be configured before importing `keras_core`, and the backend cannot be changed after
|
||||
**Note:** The backend must be configured before importing `keras`, and the backend cannot be changed after
|
||||
the package has been imported.
|
||||
|
||||
## Backwards compatibility
|
||||
|
||||
Keras Core is intended to work as a drop-in replacement for `tf.keras` (when using the TensorFlow backend). Just take your
|
||||
existing `tf.keras` code, change the `keras` imports to `keras_core`, make sure that your calls to `model.save()` are using
|
||||
Keras 3 is intended to work as a drop-in replacement for `tf.keras` (when using the TensorFlow backend). Just take your
|
||||
existing `tf.keras` code, change the `keras` imports to `keras`, make sure that your calls to `model.save()` are using
|
||||
the up-to-date `.keras` format, and you're done.
|
||||
|
||||
If your `tf.keras` model does not include custom components, you can start running it on top of JAX or PyTorch immediately.
|
||||
@ -66,7 +66,7 @@ to a backend-agnostic implementation in just a few minutes.
|
||||
In addition, Keras models can consume datasets in any format, regardless of the backend you're using:
|
||||
you can train your models with your existing `tf.data.Dataset` pipelines or PyTorch `DataLoaders`.
|
||||
|
||||
## Why use Keras Core?
|
||||
## Why use Keras 3?
|
||||
|
||||
- Run your high-level Keras workflows on top of any framework -- benefiting at will from the advantages of each framework,
|
||||
e.g. the scalability and performance of JAX or the production ecosystem options of TensorFlow.
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Benchmark the layer performance
|
||||
|
||||
This directory contains benchmarks to compare the performance of
|
||||
`keras_core.layers.XXX` and `tf.keras.layers.XXX`. We compare the performance of
|
||||
`keras.layers.XXX` and `tf.keras.layers.XXX`. We compare the performance of
|
||||
both the forward pass and train step (forward & backward pass).
|
||||
|
||||
To run the benchmark, use the command below and change the flags according to
|
||||
|
@ -4,7 +4,7 @@ import numpy as np
|
||||
import tensorflow as tf
|
||||
from absl import flags
|
||||
|
||||
import keras_core
|
||||
import keras
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
@ -66,7 +66,7 @@ class BenchmarkMetricsCallback:
|
||||
self.state["throughput"] = throughput
|
||||
|
||||
|
||||
class KerasCoreBenchmarkMetricsCallback(keras_core.callbacks.Callback):
|
||||
class KerasCoreBenchmarkMetricsCallback(keras.callbacks.Callback):
|
||||
def __init__(self, start_batch=1, stop_batch=None):
|
||||
self._callback = BenchmarkMetricsCallback(start_batch, stop_batch)
|
||||
|
||||
@ -108,21 +108,21 @@ class LayerBenchmark:
|
||||
input_shape,
|
||||
flat_call_inputs=True,
|
||||
jit_compile=True,
|
||||
keras_core_layer=None,
|
||||
keras_layer=None,
|
||||
tf_keras_layer=None,
|
||||
):
|
||||
self.layer_name = layer_name
|
||||
_keras_core_layer_class = getattr(keras_core.layers, layer_name)
|
||||
_keras_layer_class = getattr(keras.layers, layer_name)
|
||||
_tf_keras_layer_class = getattr(tf.keras.layers, layer_name)
|
||||
|
||||
if keras_core_layer is None:
|
||||
# Sometimes you want to initialize the keras_core layer and tf_keras
|
||||
if keras_layer is None:
|
||||
# Sometimes you want to initialize the keras layer and tf_keras
|
||||
# layer in a different way. For example, `Bidirectional` layer,
|
||||
# which takes in `keras_core.layers.Layer` and
|
||||
# which takes in `keras.layers.Layer` and
|
||||
# `tf.keras.layer.Layer` separately.
|
||||
self._keras_core_layer = _keras_core_layer_class(**init_args)
|
||||
self._keras_layer = _keras_layer_class(**init_args)
|
||||
else:
|
||||
self._keras_core_layer = keras_core_layer
|
||||
self._keras_layer = keras_layer
|
||||
|
||||
if tf_keras_layer is None:
|
||||
self._tf_keras_layer = _tf_keras_layer_class(**init_args)
|
||||
@ -130,14 +130,14 @@ class LayerBenchmark:
|
||||
self._tf_keras_layer = tf_keras_layer
|
||||
|
||||
self.input_shape = input_shape
|
||||
self._keras_core_model = self._build_keras_core_model(
|
||||
self._keras_model = self._build_keras_model(
|
||||
input_shape, flat_call_inputs
|
||||
)
|
||||
self._tf_keras_model = self._build_tf_keras_model(
|
||||
input_shape, flat_call_inputs
|
||||
)
|
||||
|
||||
self._keras_core_model.compile(
|
||||
self._keras_model.compile(
|
||||
loss="mse", optimizer="sgd", jit_compile=jit_compile
|
||||
)
|
||||
self._tf_keras_model.compile(
|
||||
@ -148,19 +148,19 @@ class LayerBenchmark:
|
||||
self.jit_compile = jit_compile
|
||||
self.input_shape = input_shape
|
||||
|
||||
def _build_keras_core_model(self, input_shape, flat_call_inputs=True):
|
||||
def _build_keras_model(self, input_shape, flat_call_inputs=True):
|
||||
inputs = []
|
||||
if not isinstance(input_shape[0], (tuple, list)):
|
||||
input_shape = [input_shape]
|
||||
|
||||
for shape in input_shape:
|
||||
inputs.append(keras_core.Input(shape=shape))
|
||||
inputs.append(keras.Input(shape=shape))
|
||||
|
||||
if flat_call_inputs:
|
||||
outputs = self._keras_core_layer(*inputs)
|
||||
outputs = self._keras_layer(*inputs)
|
||||
else:
|
||||
outputs = self._keras_core_layer(inputs)
|
||||
return keras_core.Model(inputs=inputs, outputs=outputs)
|
||||
outputs = self._keras_layer(inputs)
|
||||
return keras.Model(inputs=inputs, outputs=outputs)
|
||||
|
||||
def _build_tf_keras_model(self, input_shape, flat_call_inputs=True):
|
||||
inputs = []
|
||||
@ -195,7 +195,7 @@ class LayerBenchmark:
|
||||
stop_batch=num_iterations
|
||||
)
|
||||
|
||||
self._keras_core_model.predict(
|
||||
self._keras_model.predict(
|
||||
data,
|
||||
batch_size=batch_size,
|
||||
callbacks=[callback],
|
||||
@ -207,15 +207,15 @@ class LayerBenchmark:
|
||||
callbacks=[tf_keras_callback],
|
||||
)
|
||||
|
||||
keras_core_throughput = (
|
||||
keras_throughput = (
|
||||
callback._callback.state["throughput"] * batch_size
|
||||
)
|
||||
tf_keras_throughput = (
|
||||
tf_keras_callback._callback.state["throughput"] * batch_size
|
||||
)
|
||||
print(
|
||||
f"Keras Core throughput of forward pass of {self.layer_name}: "
|
||||
f"{keras_core_throughput:.2f} samples/sec."
|
||||
f"Keras 3 throughput of forward pass of {self.layer_name}: "
|
||||
f"{keras_throughput:.2f} samples/sec."
|
||||
)
|
||||
print(
|
||||
f"TF Keras throughput of forward pass of {self.layer_name}: "
|
||||
@ -240,15 +240,15 @@ class LayerBenchmark:
|
||||
if self.flat_call_inputs:
|
||||
# Scale by a small factor to avoid zero gradients.
|
||||
label = (
|
||||
keras_core.backend.convert_to_numpy(
|
||||
self._keras_core_layer(*data)
|
||||
keras.backend.convert_to_numpy(
|
||||
self._keras_layer(*data)
|
||||
)
|
||||
* 1.001
|
||||
)
|
||||
else:
|
||||
label = (
|
||||
keras_core.backend.convert_to_numpy(
|
||||
self._keras_core_layer(data)
|
||||
keras.backend.convert_to_numpy(
|
||||
self._keras_layer(data)
|
||||
)
|
||||
* 1.001
|
||||
)
|
||||
@ -259,7 +259,7 @@ class LayerBenchmark:
|
||||
stop_batch=num_iterations
|
||||
)
|
||||
|
||||
self._keras_core_model.fit(
|
||||
self._keras_model.fit(
|
||||
data,
|
||||
label,
|
||||
batch_size=batch_size,
|
||||
@ -272,15 +272,15 @@ class LayerBenchmark:
|
||||
callbacks=[tf_keras_callback],
|
||||
)
|
||||
|
||||
keras_core_throughput = (
|
||||
keras_throughput = (
|
||||
callback._callback.state["throughput"] * batch_size
|
||||
)
|
||||
tf_keras_throughput = (
|
||||
tf_keras_callback._callback.state["throughput"] * batch_size
|
||||
)
|
||||
print(
|
||||
f"Keras Core throughput of forward & backward pass of "
|
||||
f"{self.layer_name}: {keras_core_throughput:.2f} samples/sec."
|
||||
f"Keras 3 throughput of forward & backward pass of "
|
||||
f"{self.layer_name}: {keras_throughput:.2f} samples/sec."
|
||||
)
|
||||
print(
|
||||
f"TF Keras throughput of forward & backward pass of "
|
||||
|
@ -16,7 +16,7 @@ import tensorflow as tf
|
||||
from absl import app
|
||||
from absl import flags
|
||||
|
||||
import keras_core
|
||||
import keras
|
||||
from benchmarks.layer_benchmark.base_benchmark import LayerBenchmark
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
@ -194,8 +194,8 @@ def benchmark_bidirectional(
|
||||
):
|
||||
layer_name = "Bidirectional"
|
||||
init_args = {}
|
||||
keras_core_layer = keras_core.layers.Bidirectional(
|
||||
keras_core.layers.LSTM(32)
|
||||
keras_layer = keras.layers.Bidirectional(
|
||||
keras.layers.LSTM(32)
|
||||
)
|
||||
tf_keras_layer = tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(32))
|
||||
benchmark = LayerBenchmark(
|
||||
@ -203,7 +203,7 @@ def benchmark_bidirectional(
|
||||
init_args,
|
||||
input_shape=[256, 256],
|
||||
jit_compile=jit_compile,
|
||||
keras_core_layer=keras_core_layer,
|
||||
keras_layer=keras_layer,
|
||||
tf_keras_layer=tf_keras_layer,
|
||||
)
|
||||
|
||||
@ -225,8 +225,8 @@ def benchmark_time_distributed(
|
||||
):
|
||||
layer_name = "TimeDistributed"
|
||||
init_args = {}
|
||||
keras_core_layer = keras_core.layers.TimeDistributed(
|
||||
keras_core.layers.Conv2D(16, (3, 3))
|
||||
keras_layer = keras.layers.TimeDistributed(
|
||||
keras.layers.Conv2D(16, (3, 3))
|
||||
)
|
||||
tf_keras_layer = tf.keras.layers.TimeDistributed(
|
||||
tf.keras.layers.Conv2D(16, (3, 3))
|
||||
@ -236,7 +236,7 @@ def benchmark_time_distributed(
|
||||
init_args,
|
||||
input_shape=[10, 32, 32, 3],
|
||||
jit_compile=jit_compile,
|
||||
keras_core_layer=keras_core_layer,
|
||||
keras_layer=keras_layer,
|
||||
tf_keras_layer=tf_keras_layer,
|
||||
)
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import time
|
||||
|
||||
import keras_core
|
||||
import keras
|
||||
|
||||
|
||||
class BenchmarkMetricsCallback(keras_core.callbacks.Callback):
|
||||
class BenchmarkMetricsCallback(keras.callbacks.Callback):
|
||||
def __init__(self, start_batch=1, stop_batch=None):
|
||||
self.start_batch = start_batch
|
||||
self.stop_batch = stop_batch
|
||||
|
@ -21,7 +21,7 @@ from absl import flags
|
||||
from absl import logging
|
||||
from model_benchmark.benchmark_utils import BenchmarkMetricsCallback
|
||||
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
flags.DEFINE_string("model_size", "small", "The size of model to benchmark.")
|
||||
flags.DEFINE_string(
|
||||
|
@ -27,7 +27,7 @@ from absl import flags
|
||||
from absl import logging
|
||||
from model_benchmark.benchmark_utils import BenchmarkMetricsCallback
|
||||
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
flags.DEFINE_string("model", "EfficientNetV2B0", "The model to benchmark.")
|
||||
flags.DEFINE_integer("epochs", 1, "The number of epochs.")
|
||||
|
@ -9,9 +9,9 @@ import torch
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
|
||||
import keras_core
|
||||
import keras
|
||||
from benchmarks.torch_ctl_benchmark.benchmark_utils import train_loop
|
||||
from keras_core import layers
|
||||
from keras import layers
|
||||
|
||||
num_classes = 2
|
||||
input_shape = (3, 256, 256)
|
||||
@ -55,8 +55,8 @@ class TorchModel(torch.nn.Module):
|
||||
return x
|
||||
|
||||
|
||||
def run_keras_core_custom_training_loop():
|
||||
keras_model = keras_core.Sequential(
|
||||
def run_keras_custom_training_loop():
|
||||
keras_model = keras.Sequential(
|
||||
[
|
||||
layers.Input(shape=input_shape),
|
||||
layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
|
||||
@ -74,7 +74,7 @@ def run_keras_core_custom_training_loop():
|
||||
num_epochs=num_epochs,
|
||||
optimizer=optimizer,
|
||||
loss_fn=loss_fn,
|
||||
framework="keras_core",
|
||||
framework="keras",
|
||||
)
|
||||
|
||||
|
||||
@ -93,5 +93,5 @@ def run_torch_custom_training_loop():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_keras_core_custom_training_loop()
|
||||
run_keras_custom_training_loop()
|
||||
run_torch_custom_training_loop()
|
||||
|
@ -9,9 +9,9 @@ import torch
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
|
||||
import keras_core
|
||||
import keras
|
||||
from benchmarks.torch_ctl_benchmark.benchmark_utils import train_loop
|
||||
from keras_core import layers
|
||||
from keras import layers
|
||||
|
||||
num_classes = 2
|
||||
input_shape = (8192,)
|
||||
@ -55,8 +55,8 @@ class TorchModel(torch.nn.Module):
|
||||
return x
|
||||
|
||||
|
||||
def run_keras_core_custom_training_loop():
|
||||
keras_model = keras_core.Sequential(
|
||||
def run_keras_custom_training_loop():
|
||||
keras_model = keras.Sequential(
|
||||
[
|
||||
layers.Input(shape=input_shape),
|
||||
layers.Dense(64, activation="relu"),
|
||||
@ -73,7 +73,7 @@ def run_keras_core_custom_training_loop():
|
||||
num_epochs=num_epochs,
|
||||
optimizer=optimizer,
|
||||
loss_fn=loss_fn,
|
||||
framework="keras_core",
|
||||
framework="keras",
|
||||
)
|
||||
|
||||
|
||||
@ -92,5 +92,5 @@ def run_torch_custom_training_loop():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_keras_core_custom_training_loop()
|
||||
run_keras_custom_training_loop()
|
||||
run_torch_custom_training_loop()
|
||||
|
@ -26,10 +26,10 @@ flag_management:
|
||||
- type: patch
|
||||
target: auto
|
||||
individual_flags:
|
||||
- name: keras_core
|
||||
- name: keras
|
||||
paths:
|
||||
- keras_core
|
||||
- name: keras_core.applications
|
||||
- keras
|
||||
- name: keras.applications
|
||||
paths:
|
||||
- keras_core/applications
|
||||
- keras/applications
|
||||
carryforward: true
|
||||
|
@ -8,7 +8,7 @@ except ImportError:
|
||||
|
||||
import pytest
|
||||
|
||||
from keras_core.backend import backend
|
||||
from keras.backend import backend
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
|
@ -7,12 +7,12 @@ os.environ["KERAS_BACKEND"] = "jax"
|
||||
import jax
|
||||
import numpy as np
|
||||
|
||||
from keras_core import Model
|
||||
from keras_core import backend
|
||||
from keras_core import initializers
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
from keras_core import optimizers
|
||||
from keras import Model
|
||||
from keras import backend
|
||||
from keras import initializers
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
from keras import optimizers
|
||||
|
||||
|
||||
class MyDense(layers.Layer):
|
||||
|
@ -1,13 +1,13 @@
|
||||
import numpy as np
|
||||
|
||||
import keras_core
|
||||
from keras_core import Model
|
||||
from keras_core import initializers
|
||||
from keras_core import layers
|
||||
from keras_core import losses
|
||||
from keras_core import metrics
|
||||
from keras_core import ops
|
||||
from keras_core import optimizers
|
||||
import keras
|
||||
from keras import Model
|
||||
from keras import initializers
|
||||
from keras import layers
|
||||
from keras import losses
|
||||
from keras import metrics
|
||||
from keras import ops
|
||||
from keras import optimizers
|
||||
|
||||
|
||||
class MyDense(layers.Layer):
|
||||
@ -43,11 +43,11 @@ class MyDropout(layers.Layer):
|
||||
# Use seed_generator for managing RNG state.
|
||||
# It is a state element and its seed variable is
|
||||
# tracked as part of `layer.variables`.
|
||||
self.seed_generator = keras_core.random.SeedGenerator(1337)
|
||||
self.seed_generator = keras.random.SeedGenerator(1337)
|
||||
|
||||
def call(self, inputs):
|
||||
# Use `keras_core.random` for random ops.
|
||||
return keras_core.random.dropout(
|
||||
# Use `keras.random` for random ops.
|
||||
return keras.random.dropout(
|
||||
inputs, self.rate, seed=self.seed_generator
|
||||
)
|
||||
|
||||
|
@ -7,12 +7,12 @@ os.environ["KERAS_BACKEND"] = "tensorflow"
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
|
||||
from keras_core import Model
|
||||
from keras_core import backend
|
||||
from keras_core import initializers
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
from keras_core import optimizers
|
||||
from keras import Model
|
||||
from keras import backend
|
||||
from keras import initializers
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
from keras import optimizers
|
||||
|
||||
|
||||
class MyDense(layers.Layer):
|
||||
|
@ -7,8 +7,8 @@ os.environ["KERAS_BACKEND"] = "torch"
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
from keras_core import layers
|
||||
import keras_core
|
||||
from keras import layers
|
||||
import keras
|
||||
import numpy as np
|
||||
|
||||
# Model / data parameters
|
||||
@ -19,7 +19,7 @@ batch_size = 64
|
||||
num_epochs = 1
|
||||
|
||||
# Load the data and split it between train and test sets
|
||||
(x_train, y_train), (x_test, y_test) = keras_core.datasets.mnist.load_data()
|
||||
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
|
||||
|
||||
# Scale images to the [0, 1] range
|
||||
x_train = x_train.astype("float32") / 255
|
||||
@ -32,7 +32,7 @@ print(x_train.shape[0], "train samples")
|
||||
print(x_test.shape[0], "test samples")
|
||||
|
||||
# Create the Keras model
|
||||
model = keras_core.Sequential(
|
||||
model = keras.Sequential(
|
||||
[
|
||||
layers.Input(shape=(28, 28, 1)),
|
||||
layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
|
||||
@ -102,7 +102,7 @@ train(model, train_loader, num_epochs, optimizer, loss_fn)
|
||||
class MyModel(nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.model = keras_core.Sequential(
|
||||
self.model = keras.Sequential(
|
||||
[
|
||||
layers.Input(shape=(28, 28, 1)),
|
||||
layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
|
||||
|
@ -11,7 +11,7 @@ pp = pprint.PrettyPrinter()
|
||||
import jax
|
||||
import jax.numpy as jnp
|
||||
import tensorflow as tf # just for tf.data
|
||||
import keras_core as keras # Keras multi-backend
|
||||
import keras as keras # Keras multi-backend
|
||||
|
||||
import numpy as np
|
||||
from tqdm import tqdm
|
||||
|
@ -1,14 +1,14 @@
|
||||
import numpy as np
|
||||
import keras_core
|
||||
from keras_core import layers
|
||||
from keras_core.utils import to_categorical
|
||||
import keras
|
||||
from keras import layers
|
||||
from keras.utils import to_categorical
|
||||
|
||||
# Model / data parameters
|
||||
num_classes = 10
|
||||
input_shape = (28, 28, 1)
|
||||
|
||||
# Load the data and split it between train and test sets
|
||||
(x_train, y_train), (x_test, y_test) = keras_core.datasets.mnist.load_data()
|
||||
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
|
||||
|
||||
# Scale images to the [0, 1] range
|
||||
x_train = x_train.astype("float32") / 255
|
||||
@ -28,7 +28,7 @@ y_test = to_categorical(y_test, num_classes)
|
||||
batch_size = 128
|
||||
epochs = 3
|
||||
|
||||
model = keras_core.Sequential(
|
||||
model = keras.Sequential(
|
||||
[
|
||||
layers.Input(shape=input_shape),
|
||||
layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
|
||||
|
@ -1,10 +1,10 @@
|
||||
import numpy as np
|
||||
|
||||
from keras_core import Model
|
||||
from keras_core import layers
|
||||
from keras_core import losses
|
||||
from keras_core import metrics
|
||||
from keras_core import optimizers
|
||||
from keras import Model
|
||||
from keras import layers
|
||||
from keras import losses
|
||||
from keras import metrics
|
||||
from keras import optimizers
|
||||
|
||||
|
||||
class MyModel(Model):
|
||||
|
@ -7,8 +7,8 @@ os.environ["KERAS_BACKEND"] = "torch"
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
from keras_core import layers
|
||||
import keras_core
|
||||
from keras import layers
|
||||
import keras
|
||||
import numpy as np
|
||||
|
||||
import torch.multiprocessing as mp
|
||||
@ -27,7 +27,7 @@ num_epochs = 1
|
||||
|
||||
def get_data():
|
||||
# Load the data and split it between train and test sets
|
||||
(x_train, y_train), (x_test, y_test) = keras_core.datasets.mnist.load_data()
|
||||
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
|
||||
|
||||
# Scale images to the [0, 1] range
|
||||
x_train = x_train.astype("float32") / 255
|
||||
@ -48,7 +48,7 @@ def get_data():
|
||||
|
||||
def get_model():
|
||||
# Create the Keras model
|
||||
model = keras_core.Sequential(
|
||||
model = keras.Sequential(
|
||||
[
|
||||
layers.Input(shape=(28, 28, 1)),
|
||||
layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
|
||||
@ -66,7 +66,7 @@ def get_model():
|
||||
class MyModel(nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.model = keras_core.Sequential(
|
||||
self.model = keras.Sequential(
|
||||
[
|
||||
layers.Input(shape=(28, 28, 1)),
|
||||
layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
|
||||
|
@ -41,7 +41,7 @@ import os
|
||||
os.environ["KERAS_BACKEND"] = "jax"
|
||||
|
||||
import keras_nlp
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
import tensorflow.data as tf_data
|
||||
import tensorflow.strings as tf_strings
|
||||
|
@ -42,10 +42,10 @@ with TensorFlow 2.3 or higher.
|
||||
import os
|
||||
os.environ['KERAS_BACKEND'] = 'tensorflow'
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
from keras_core.layers import TextVectorization
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
from keras.layers import TextVectorization
|
||||
import numpy as np
|
||||
import os
|
||||
import string
|
||||
|
@ -46,8 +46,8 @@ Five digits (reversed):
|
||||
## Setup
|
||||
"""
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
import numpy as np
|
||||
|
||||
# Parameters for the model and dataset.
|
||||
|
@ -11,8 +11,8 @@ Accelerator: GPU
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
max_features = 20000 # Only consider the top 20k words
|
||||
maxlen = 200 # Only consider the first 200 words of each movie review
|
||||
|
@ -21,7 +21,7 @@ unlike question answering. We will use SWAG dataset to demonstrate this example.
|
||||
"""
|
||||
|
||||
"""shell
|
||||
pip install -q keras-core --upgrade
|
||||
pip install -q keras --upgrade
|
||||
pip install -q keras-nlp --upgrade
|
||||
"""
|
||||
|
||||
@ -29,7 +29,7 @@ import os
|
||||
os.environ["KERAS_BACKEND"] = "jax" # or "tensorflow" or "torch"
|
||||
|
||||
import keras_nlp
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import tensorflow as tf
|
||||
|
||||
import numpy as np
|
||||
@ -194,7 +194,7 @@ content of the options themselves, rather than being influenced by their positio
|
||||
|
||||
**Note:** Even though `option_shuffle` function is written in pure
|
||||
tensorflow, it can be used with any backend (e.g. JAX, PyTorch) as it is only used
|
||||
in `tf.data.Dataset` pipeline which is compatible with Keras Core routines.
|
||||
in `tf.data.Dataset` pipeline which is compatible with Keras 3 routines.
|
||||
"""
|
||||
|
||||
|
||||
|
@ -52,8 +52,8 @@ import keras_nlp
|
||||
import pathlib
|
||||
import random
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import ops
|
||||
|
||||
import tensorflow.data as tf_data
|
||||
from tensorflow_text.tools.wordpiece_vocab import (
|
||||
|
@ -53,10 +53,10 @@ import numpy as np
|
||||
import tensorflow.data as tf_data
|
||||
import tensorflow.strings as tf_strings
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
from keras_core.layers import TextVectorization
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
from keras.layers import TextVectorization
|
||||
|
||||
"""
|
||||
## Downloading the data
|
||||
@ -231,7 +231,7 @@ sure that it only uses information from target tokens 0 to N when predicting tok
|
||||
(otherwise, it could use information from the future, which would
|
||||
result in a model that cannot be used at inference time).
|
||||
"""
|
||||
import keras_core.ops as ops
|
||||
import keras.ops as ops
|
||||
|
||||
class TransformerEncoder(layers.Layer):
|
||||
def __init__(self, embed_dim, dense_dim, num_heads, **kwargs):
|
||||
|
@ -84,7 +84,7 @@ import nltk
|
||||
import random
|
||||
import logging
|
||||
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
nltk.download("punkt")
|
||||
# Set random seed
|
||||
|
@ -21,7 +21,7 @@ Dataloaders](https://pytorch.org/tutorials/beginner/basics/data_tutorial.html).
|
||||
### References:
|
||||
|
||||
- [Customizing what happens in `fit()` with
|
||||
PyTorch](https://keras.io/keras_core/guides/custom_train_step_in_torch/)
|
||||
PyTorch](https://keras.io/keras/guides/custom_train_step_in_torch/)
|
||||
- [PyTorch Datasets and
|
||||
Dataloaders](https://pytorch.org/tutorials/beginner/basics/data_tutorial.html)
|
||||
- [Transfer learning for Computer Vision using
|
||||
@ -46,8 +46,8 @@ import torch.nn.functional as F
|
||||
import torchvision
|
||||
from torchvision import datasets, models, transforms
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core.layers import TorchModuleWrapper
|
||||
import keras as keras
|
||||
from keras.layers import TorchModuleWrapper
|
||||
|
||||
"""
|
||||
## Define the Hyperparameters
|
||||
@ -165,9 +165,9 @@ resnet_18.fc = nn.Identity()
|
||||
|
||||
"""
|
||||
Even though Keras supports PyTorch as a backend, it does not mean that we can nest torch
|
||||
modules inside a [`keras_core.Model`](https://keras.io/keras_core/api/models/), because
|
||||
modules inside a [`keras.Model`](https://keras.io/keras/api/models/), because
|
||||
trainable variables inside a Keras Model is tracked exclusively via [Keras
|
||||
Layers](https://keras.io/keras_core/api/layers/).
|
||||
Layers](https://keras.io/keras/api/layers/).
|
||||
|
||||
KerasCore provides us with a feature called `TorchModuleWrapper` which enables us to do
|
||||
exactly this. The `TorchModuleWrapper` is a Keras Layer that accepts a torch module and
|
||||
|
@ -37,9 +37,9 @@ import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from zipfile import ZipFile
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
|
||||
"""
|
||||
## First, load the data and apply preprocessing
|
||||
|
@ -33,10 +33,10 @@ and 9 categorical features.
|
||||
## Setup
|
||||
"""
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core.layers import StringLookup
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras.layers import StringLookup
|
||||
from keras import ops
|
||||
|
||||
|
||||
from tensorflow import data as tf_data
|
||||
|
@ -21,9 +21,9 @@ into robust contextual embeddings to achieve higher predictive accuracy.
|
||||
|
||||
## Setup
|
||||
"""
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
|
||||
import math
|
||||
import numpy as np
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Speaker Recognition
|
||||
Author: [Fadi Badine](https://twitter.com/fadibadine)
|
||||
Converted to Keras Core by: [Fadi Badine](https://twitter.com/fadibadine)
|
||||
Converted to Keras 3 by: [Fadi Badine](https://twitter.com/fadibadine)
|
||||
Date created: 14/06/2020
|
||||
Last modified: 19/07/2023
|
||||
Description: Classify speakers using Fast Fourier Transform (FFT) and a 1D Convnet.
|
||||
@ -47,7 +47,7 @@ import shutil
|
||||
import numpy as np
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
from pathlib import Path
|
||||
from IPython.display import display, Audio
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: English speaker accent recognition using Transfer Learning
|
||||
Author: [Fadi Badine](https://twitter.com/fadibadine)
|
||||
Converted to Keras Core by: [Fadi Badine](https://twitter.com/fadibadine)
|
||||
Converted to Keras 3 by: [Fadi Badine](https://twitter.com/fadibadine)
|
||||
Date created: 2022/04/16
|
||||
Last modified: 2023/07/19
|
||||
Description: Training a model to classify UK & Ireland accents using feature extraction from Yamnet.
|
||||
@ -108,7 +108,7 @@ import pandas as pd
|
||||
import tensorflow as tf
|
||||
import tensorflow_hub as hub
|
||||
import tensorflow_io as tfio
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
from scipy import stats
|
||||
|
@ -27,9 +27,9 @@ using cycle-consistent adversarial networks.
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
|
||||
import tensorflow as tf
|
||||
import tensorflow_datasets as tfds
|
||||
@ -664,13 +664,13 @@ and try the demo on [Hugging Face Spaces](https://huggingface.co/spaces/keras-io
|
||||
# data and check the model's performance.
|
||||
|
||||
"""shell
|
||||
curl -LO https://github.com/freedomtan/cyclegan-keras-core/archive/refs/tags/2.0.zip
|
||||
curl -LO https://github.com/freedomtan/cyclegan-keras/archive/refs/tags/2.0.zip
|
||||
unzip -qq 2.0.zip
|
||||
"""
|
||||
|
||||
|
||||
# Load the checkpoints
|
||||
weight_file = "./cyclegan-keras-core-2.0/model_checkpoints/cyclegan_checkpoints.090.weights.h5"
|
||||
weight_file = "./cyclegan-keras-2.0/model_checkpoints/cyclegan_checkpoints.090.weights.h5"
|
||||
cycle_gan_model.load_weights(weight_file)
|
||||
print("Weights loaded successfully")
|
||||
|
||||
|
@ -11,8 +11,8 @@ Accelerator: GPU
|
||||
"""
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
import matplotlib.pyplot as plt
|
||||
import os
|
||||
import gdown
|
||||
|
@ -72,9 +72,9 @@ import matplotlib.pyplot as plt
|
||||
import tensorflow as tf
|
||||
import tensorflow_datasets as tfds
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
|
||||
"""
|
||||
## Hyperparameters
|
||||
|
@ -90,8 +90,8 @@ import matplotlib.pyplot as plt
|
||||
|
||||
# Requires TensorFlow >=2.11 for the GroupNormalization layer.
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
import tensorflow_datasets as tfds
|
||||
|
||||
"""
|
||||
|
@ -38,8 +38,8 @@ and compare the result to the (resized) original image.
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core.applications import inception_v3
|
||||
import keras as keras
|
||||
from keras.applications import inception_v3
|
||||
|
||||
base_image_path = keras.utils.get_file(
|
||||
"sky.jpg", "https://i.imgur.com/aGBdQyK.jpg"
|
||||
|
@ -25,8 +25,8 @@ has at least ~100k characters. ~1M is better.
|
||||
"""
|
||||
## Setup
|
||||
"""
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
import numpy as np
|
||||
import random
|
||||
|
@ -40,8 +40,8 @@ keeping the generated image close enough to the original one.
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core.applications import vgg19
|
||||
import keras as keras
|
||||
from keras.applications import vgg19
|
||||
|
||||
base_image_path = keras.utils.get_file(
|
||||
"paris.jpg", "https://i.imgur.com/F28w3Ac.jpg"
|
||||
|
@ -13,8 +13,8 @@ Accelerator: GPU
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## Create a sampling layer
|
||||
|
@ -30,8 +30,8 @@ that keeps the L2 norm of the discriminator gradients close to 1.
|
||||
"""
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
|
||||
"""
|
||||
|
@ -23,8 +23,8 @@ features back to a space of the original size.
|
||||
"""
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## The Antirectifier layer
|
||||
|
@ -12,7 +12,7 @@ Accelerator: GPU
|
||||
"""
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import numpy as np
|
||||
|
||||
"""
|
||||
|
@ -27,8 +27,8 @@ Using this approach, we can quickly implement a
|
||||
[StandardizedConv2D](https://arxiv.org/abs/1903.10520) as shown below.
|
||||
"""
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
import numpy as np
|
||||
|
||||
|
||||
|
@ -29,8 +29,8 @@ TensorFlow NumPy requires TensorFlow 2.5 or later.
|
||||
|
||||
import tensorflow as tf
|
||||
import tensorflow.experimental.numpy as tnp
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
Optionally, you can call `tnp.experimental_enable_numpy_behavior()` to enable type promotion in TensorFlow.
|
||||
|
@ -60,7 +60,7 @@ import shutil
|
||||
import requests
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
"""
|
||||
|
@ -25,7 +25,7 @@ by putting the custom training step in the Trainer class definition.
|
||||
"""
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
# Load MNIST dataset and standardize the data
|
||||
mnist = keras.datasets.mnist
|
||||
|
@ -50,8 +50,8 @@ from pathlib import Path
|
||||
from dataclasses import dataclass
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## Configuration
|
||||
|
@ -47,7 +47,7 @@ models are more common in this domain.
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
@ -34,8 +34,8 @@ wget https://raw.githubusercontent.com/sighsmile/conlleval/master/conlleval.py
|
||||
|
||||
import os
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from datasets import load_dataset
|
||||
from collections import Counter
|
||||
from conlleval import evaluate
|
||||
|
@ -13,7 +13,7 @@ Accelerator: GPU
|
||||
|
||||
import numpy as np
|
||||
import tensorflow.data as tf_data
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
"""
|
||||
## Introduction
|
||||
@ -123,7 +123,7 @@ Our layer will only consider the top 20,000 words, and will truncate or pad sequ
|
||||
be actually 200 tokens long.
|
||||
"""
|
||||
|
||||
from keras_core.layers import TextVectorization
|
||||
from keras.layers import TextVectorization
|
||||
|
||||
vectorizer = TextVectorization(max_tokens=20000, output_sequence_length=200)
|
||||
text_ds = tf_data.Dataset.from_tensor_slices(train_samples).batch(128)
|
||||
@ -228,7 +228,7 @@ Note that we set `trainable=False` so as to keep the embeddings fixed (we don't
|
||||
update them during training).
|
||||
"""
|
||||
|
||||
from keras_core.layers import Embedding
|
||||
from keras.layers import Embedding
|
||||
|
||||
embedding_layer = Embedding(
|
||||
num_tokens,
|
||||
@ -244,7 +244,7 @@ embedding_layer.set_weights([embedding_matrix])
|
||||
A simple 1D convnet with global max pooling and a classifier at the end.
|
||||
"""
|
||||
|
||||
from keras_core import layers
|
||||
from keras import layers
|
||||
|
||||
int_sequences_input = keras.Input(shape=(None,), dtype="int64")
|
||||
embedded_sequences = embedding_layer(int_sequences_input)
|
||||
|
@ -20,9 +20,9 @@ classification dataset (unprocessed version). We use the `TextVectorization` lay
|
||||
"""
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core.layers import TextVectorization
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras.layers import TextVectorization
|
||||
from keras import layers
|
||||
import string
|
||||
import re
|
||||
import os
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Actor Critic Method
|
||||
Author: [Apoorv Nandan](https://twitter.com/NandanApoorv)
|
||||
Converted to Keras Core by: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Converted to Keras 3 by: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Date created: 2020/05/13
|
||||
Last modified: 2023/07/19
|
||||
Description: Implement Actor Critic Method in CartPole environment.
|
||||
@ -44,8 +44,8 @@ import os
|
||||
|
||||
os.environ["KERAS_BACKEND"] = "tensorflow"
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
import gym
|
||||
import numpy as np
|
||||
|
@ -20,7 +20,7 @@ to train a classification model on data with highly imbalanced classes.
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
# Get the real data from https://www.kaggle.com/mlg-ulb/creditcardfraud/
|
||||
fname = "/Users/fchollet/Downloads/creditcard.csv"
|
||||
|
@ -51,8 +51,8 @@ Target | Diagnosis of heart disease (1 = true; 0 = false) | Target
|
||||
|
||||
import tensorflow as tf
|
||||
import pandas as pd
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## Preparing the data
|
||||
@ -172,9 +172,9 @@ then one-hot encode these integer indices.
|
||||
- `encode_integer_categorical_feature` to one-hot encode integer categorical features.
|
||||
"""
|
||||
|
||||
from keras_core.layers import IntegerLookup
|
||||
from keras_core.layers import Normalization
|
||||
from keras_core.layers import StringLookup
|
||||
from keras.layers import IntegerLookup
|
||||
from keras.layers import Normalization
|
||||
from keras.layers import StringLookup
|
||||
|
||||
|
||||
def encode_numerical_feature(feature, name, dataset):
|
||||
|
@ -61,8 +61,8 @@ Target | Diagnosis of heart disease (1 = true; 0 = false) | Target
|
||||
|
||||
import tensorflow as tf
|
||||
import pandas as pd
|
||||
import keras_core as keras
|
||||
from keras_core.utils import FeatureSpace
|
||||
import keras as keras
|
||||
from keras.utils import FeatureSpace
|
||||
|
||||
keras.config.disable_traceback_filtering()
|
||||
|
||||
|
@ -65,8 +65,8 @@ import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import json
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
import tensorflow as tf
|
||||
from sklearn import preprocessing, model_selection
|
||||
import random
|
||||
|
@ -47,9 +47,9 @@ import typing
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core.utils import timeseries_dataset_from_array
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras.utils import timeseries_dataset_from_array
|
||||
|
||||
"""
|
||||
## Data preparation
|
||||
|
@ -14,7 +14,7 @@ This example requires TensorFlow 2.3 or higher.
|
||||
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
"""
|
||||
## Climate Data Time-Series
|
||||
|
@ -42,7 +42,7 @@ import os
|
||||
|
||||
os.environ["KERAS_BACKEND"] = "tensorflow"
|
||||
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: CutMix data augmentation for image classification
|
||||
Author: [Sayan Nath](https://twitter.com/sayannath2350)
|
||||
Converted to Keras Core By: [Piyush Thakur](https://github.com/cosmo3769)
|
||||
Converted to Keras 3 By: [Piyush Thakur](https://github.com/cosmo3769)
|
||||
Date created: 2021/06/08
|
||||
Last modified: 2023/07/24
|
||||
Description: Data augmentation with CutMix for image classification on CIFAR-10.
|
||||
@ -48,10 +48,10 @@ where `rx, ry` are randomly drawn from a uniform distribution with upper bound.
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from keras_core import layers
|
||||
from keras import layers
|
||||
|
||||
# TF imports related to tf.data preprocessing
|
||||
from tensorflow import clip_by_value
|
||||
|
@ -49,8 +49,8 @@ os.environ["KERAS_BACKEND"] = "tensorflow"
|
||||
|
||||
import tensorflow as tf
|
||||
import tensorflow_datasets as tfds
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
tfds.disable_progress_bar()
|
||||
keras.utils.set_random_seed(42)
|
||||
|
@ -13,7 +13,7 @@ Adapted from Deep Learning with Python (2017).
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
# Display
|
||||
from IPython.display import Image, display
|
||||
|
@ -17,10 +17,10 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core.applications import efficientnet
|
||||
from keras_core.layers import TextVectorization
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras.applications import efficientnet
|
||||
from keras.layers import TextVectorization
|
||||
|
||||
|
||||
seed = 111
|
||||
|
@ -23,8 +23,8 @@ we use Keras image preprocessing layers for image standardization and data augme
|
||||
"""
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
import os
|
||||
from pathlib import Path
|
||||
import matplotlib.pyplot as plt
|
||||
|
@ -58,9 +58,9 @@ from scipy import ndimage
|
||||
from IPython.display import Image, display
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core.applications import xception
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras.applications import xception
|
||||
|
||||
keras.config.disable_traceback_filtering()
|
||||
|
||||
|
@ -36,7 +36,7 @@ layer.
|
||||
"""
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Set seed for reproducibility.
|
||||
|
@ -32,9 +32,9 @@ import tensorflow as tf
|
||||
from collections import defaultdict
|
||||
from PIL import Image
|
||||
from sklearn.metrics import ConfusionMatrixDisplay
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core.datasets import cifar10
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras.datasets import cifar10
|
||||
|
||||
"""
|
||||
## Dataset
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Low-light image enhancement using MIRNet
|
||||
Author: [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Converted to Keras Core by: [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Converted to Keras 3 by: [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Date created: 2021/09/11
|
||||
Last modified: 2023/07/15
|
||||
Description: Implementing the MIRNet architecture for low-light image enhancement.
|
||||
@ -34,7 +34,7 @@ consists of a low-light input image and its corresponding well-exposed reference
|
||||
"""
|
||||
|
||||
"""shell
|
||||
pip install -q git+https://github.com/keras-team/keras-core
|
||||
pip install -q git+https://github.com/keras-team/keras
|
||||
"""
|
||||
|
||||
import os
|
||||
@ -47,8 +47,8 @@ from glob import glob
|
||||
from PIL import Image, ImageOps
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
|
@ -37,10 +37,10 @@ processing, speech, and so on.
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from keras_core import layers
|
||||
from keras import layers
|
||||
|
||||
# TF imports related to tf.data preprocessing
|
||||
from tensorflow import data as tf_data
|
||||
|
@ -43,8 +43,8 @@ pip install -U tensorflow-addons
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## Prepare the data
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Few-Shot learning with Reptile
|
||||
Author: [ADMoreau](https://github.com/ADMoreau)
|
||||
Converted to Keras Core By: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Converted to Keras 3 By: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Date created: 2020/05/21
|
||||
Last modified: 2023/07/20
|
||||
Description: Few-shot classification on the Omniglot dataset using Reptile.
|
||||
@ -22,8 +22,8 @@ import os
|
||||
|
||||
os.environ["KERAS_BACKEND"] = "tensorflow"
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
@ -77,8 +77,8 @@ import matplotlib.pyplot as plt
|
||||
import tensorflow as tf
|
||||
import tensorflow_datasets as tfds
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## Hyperparameter setup
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: A Vision Transformer without Attention
|
||||
Author: [Aritra Roy Gosthipaty](https://twitter.com/ariG23498), [Ritwik Raha](https://twitter.com/ritwik_raha)
|
||||
Converted to Keras Core: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Converted to Keras 3: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Date created: 2022/02/24
|
||||
Last modified: 2023/07/15
|
||||
Description: A minimal implementation of ShiftViT.
|
||||
@ -40,8 +40,8 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
|
||||
# Setting seed for reproducibiltiy
|
||||
|
@ -38,11 +38,11 @@ import numpy as np
|
||||
import os
|
||||
import tensorflow as tf
|
||||
from pathlib import Path
|
||||
from keras_core import layers
|
||||
from keras_core import optimizers
|
||||
from keras_core import metrics
|
||||
from keras_core import Model
|
||||
from keras_core.applications import resnet
|
||||
from keras import layers
|
||||
from keras import optimizers
|
||||
from keras import metrics
|
||||
from keras import Model
|
||||
from keras.applications import resnet
|
||||
|
||||
|
||||
target_shape = (200, 200)
|
||||
|
@ -49,9 +49,9 @@ versions of our dataset.
|
||||
import os
|
||||
os.environ['KERAS_BACKEND'] = 'tensorflow'
|
||||
|
||||
from keras_core import layers
|
||||
from keras_core import regularizers
|
||||
import keras_core as keras
|
||||
from keras import layers
|
||||
from keras import regularizers
|
||||
import keras as keras
|
||||
import tensorflow as tf
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
@ -29,8 +29,8 @@ This example requires TensorFlow 2.5 or higher.
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## Prepare the data
|
||||
|
@ -26,7 +26,7 @@ import os
|
||||
|
||||
os.environ["KERAS_BACKEND"] = "tensorflow"
|
||||
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
|
||||
|
||||
import numpy as np
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Zero-DCE for low-light image enhancement
|
||||
Author: [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Converted to Keras Core by: [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Converted to Keras 3 by: [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Date created: 2021/09/18
|
||||
Last modified: 2023/07/15
|
||||
Description: Implementing Zero-Reference Deep Curve Estimation for low-light image enhancement.
|
||||
@ -49,8 +49,8 @@ from glob import glob
|
||||
from PIL import Image, ImageOps
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
|
@ -20,8 +20,8 @@ autoencoder model to detect anomalies in timeseries data.
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
"""
|
||||
|
@ -19,7 +19,7 @@ CSV timeseries files on disk. We demonstrate the workflow on the FordA dataset f
|
||||
## Setup
|
||||
|
||||
"""
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
@ -62,8 +62,8 @@ You can replace your classification RNN layers with this one: the
|
||||
inputs are fully compatible!
|
||||
"""
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
We include residual connections, layer normalization, and dropout.
|
||||
|
@ -54,9 +54,9 @@ by TensorFlow.
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
from tqdm import tqdm
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
|
@ -24,9 +24,9 @@ by [François Chollet](https://twitter.com/fchollet).
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from keras_core import layers
|
||||
from keras_core.datasets import mnist
|
||||
from keras_core.models import Model
|
||||
from keras import layers
|
||||
from keras.datasets import mnist
|
||||
from keras.models import Model
|
||||
|
||||
|
||||
def preprocess(array):
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Compact Convolutional Transformers
|
||||
Author: [Sayak Paul](https://twitter.com/RisingSayak)
|
||||
Converted to Keras Core by: [Muhammad Anas Raza](https://anasrz.com), [Guillaume Baquiast](https://www.linkedin.com/in/guillaume-baquiast-478965ba/)
|
||||
Converted to Keras 3 by: [Muhammad Anas Raza](https://anasrz.com), [Guillaume Baquiast](https://www.linkedin.com/in/guillaume-baquiast-478965ba/)
|
||||
Date created: 2021/06/30
|
||||
Last modified: 2023/08/07
|
||||
Description: Compact Convolutional Transformers for efficient image classification.
|
||||
@ -39,8 +39,8 @@ code snippets from another example,
|
||||
## Imports
|
||||
"""
|
||||
|
||||
from keras_core import layers
|
||||
import keras_core as keras
|
||||
from keras import layers
|
||||
import keras as keras
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
@ -25,8 +25,8 @@ of predicting what video frames come next given a series of past frames.
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
import io
|
||||
import imageio
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Multiclass semantic segmentation using DeepLabV3+
|
||||
Author: [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Converted to Keras Core: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Converted to Keras 3: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Date created: 2021/08/31
|
||||
Last modified: 2023/07/19
|
||||
Description: Implement DeepLabV3+ architecture for Multi-class Semantic Segmentation.
|
||||
@ -32,9 +32,9 @@ This dataset can be used for the "human part segmentation" task.
|
||||
"""
|
||||
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Image classification with EANet (External Attention Transformer)
|
||||
Author: [ZhiYong Chang](https://github.com/czy00000)
|
||||
Converted to Keras Core: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Converted to Keras 3: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Date created: 2021/10/19
|
||||
Last modified: 2023/07/18
|
||||
Description: Image classification with a Transformer that leverages external attention.
|
||||
@ -25,9 +25,9 @@ implicitly considers the correlations between all samples.
|
||||
## Setup
|
||||
"""
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
@ -27,8 +27,8 @@ to fix this discrepancy.
|
||||
## Imports
|
||||
"""
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
import tensorflow as tf # just for image processing and pipeline
|
||||
|
||||
import tensorflow_datasets as tfds
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Gradient Centralization for Better Training Performance
|
||||
Author: [Rishit Dagli](https://github.com/Rishit-dagli)
|
||||
Converted to Keras Core by: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Converted to Keras 3 by: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Date created: 06/18/21
|
||||
Last modified: 07/25/23
|
||||
Description: Implement Gradient Centralization to improve training performance of DNNs.
|
||||
@ -34,10 +34,10 @@ pip install tensorflow-datasets
|
||||
|
||||
from time import time
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core.optimizers import RMSprop
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras.optimizers import RMSprop
|
||||
from keras import ops
|
||||
|
||||
from tensorflow import data as tf_data
|
||||
import tensorflow_datasets as tfds
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Image classification with Vision Transformer
|
||||
Author: [Khalid Salama](https://www.linkedin.com/in/khalid-salama-24403144/)
|
||||
Converted to Keras Core by: [divyasreepat](https://github.com/divyashreepathihalli), [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Converted to Keras 3 by: [divyasreepat](https://github.com/divyashreepathihalli), [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Date created: 2021/01/18
|
||||
Last modified: 2021/01/18
|
||||
Description: Implementing the Vision Transformer (ViT) model for image classification.
|
||||
@ -27,9 +27,9 @@ import os
|
||||
|
||||
os.environ["KERAS_BACKEND"] = "jax" # @param ["tensorflow", "jax", "torch"]
|
||||
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
@ -25,7 +25,7 @@ classification problems at three levels of complexity:
|
||||
## Multi-Backend Support
|
||||
|
||||
KerasCV's `ImageClassifier` model supports several backends like JAX, PyTorch,
|
||||
and TensorFlow with the help of `keras_core`. To enable multi-backend support
|
||||
and TensorFlow with the help of `keras`. To enable multi-backend support
|
||||
in KerasCV, set the `KERAS_CV_MULTI_BACKEND` environment variable. We can
|
||||
then switch between different backends by setting the `KERAS_BACKEND`
|
||||
environment variable. Currently, `"tensorflow"`, `"jax"`, and `"torch"` are
|
||||
@ -42,12 +42,12 @@ os.environ["KERAS_BACKEND"] = "jax"
|
||||
import json
|
||||
import math
|
||||
import keras_cv
|
||||
import keras_core as keras
|
||||
from keras_core import ops
|
||||
from keras_core import losses
|
||||
from keras_core import optimizers
|
||||
from keras_core.optimizers import schedules
|
||||
from keras_core import metrics
|
||||
import keras as keras
|
||||
from keras import ops
|
||||
from keras import losses
|
||||
from keras import optimizers
|
||||
from keras.optimizers import schedules
|
||||
from keras import metrics
|
||||
import tensorflow as tf
|
||||
from tensorflow import data as tf_data
|
||||
import tensorflow_datasets as tfds
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Keypoint Detection with Transfer Learning
|
||||
Author: [Sayak Paul](https://twitter.com/RisingSayak)
|
||||
Converted to Keras Core by: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Converted to Keras 3 by: [Muhammad Anas Raza](https://anasrz.com)
|
||||
Date created: 2021/05/02
|
||||
Last modified: 2023/07/19
|
||||
Description: Training a keypoint detector with data augmentation and transfer learning.
|
||||
@ -57,8 +57,8 @@ unzip -qq ~/stanfordextra_v12.zip
|
||||
"""
|
||||
## Imports
|
||||
"""
|
||||
from keras_core import layers
|
||||
import keras_core as keras
|
||||
from keras import layers
|
||||
import keras as keras
|
||||
|
||||
from imgaug.augmentables.kps import KeypointsOnImage
|
||||
from imgaug.augmentables.kps import Keypoint
|
||||
|
@ -39,9 +39,9 @@ using the [DenseNet-121](https://arxiv.org/abs/1608.06993) architecture.
|
||||
## Setup
|
||||
"""
|
||||
|
||||
from keras_core import layers
|
||||
import keras_core as keras
|
||||
from keras_core import ops
|
||||
from keras import layers
|
||||
import keras as keras
|
||||
from keras import ops
|
||||
|
||||
from tensorflow import data as tf_data
|
||||
from tensorflow import image as tf_image
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Image classification with modern MLP models
|
||||
Author: [Khalid Salama](https://www.linkedin.com/in/khalid-salama-24403144/)
|
||||
Converted to Keras Core by: [Guillaume Baquiast](https://www.linkedin.com/in/guillaume-baquiast-478965ba/), [divyasreepat](https://github.com/divyashreepathihalli)
|
||||
Converted to Keras 3 by: [Guillaume Baquiast](https://www.linkedin.com/in/guillaume-baquiast-478965ba/), [divyasreepat](https://github.com/divyashreepathihalli)
|
||||
Date created: 2021/05/30
|
||||
Last modified: 2023/08/03
|
||||
Description: Implementing the MLP-Mixer, FNet, and gMLP models for CIFAR-100 image classification.
|
||||
@ -29,8 +29,8 @@ main building blocks.
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## Prepare the data
|
||||
|
@ -12,8 +12,8 @@ Accelerator: GPU
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
|
||||
"""
|
||||
## Prepare the data
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Title: Object detection with Vision Transformers
|
||||
Author: [Karan V. Dave](https://www.linkedin.com/in/karan-dave-811413164/)
|
||||
Converted to Keras Core by: [Gabriel Rasskin](https://github.com/grasskin), [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Converted to Keras 3 by: [Gabriel Rasskin](https://github.com/grasskin), [Soumik Rakshit](http://github.com/soumik12345)
|
||||
Date created: 2022/03/27
|
||||
Last modified: 2022/03/27
|
||||
Description: A simple Keras implementation of object detection using Vision Transformers.
|
||||
@ -29,7 +29,7 @@ from which we import the `AdamW` optimizer.
|
||||
TensorFlow Addons can be installed via the following command:
|
||||
|
||||
```
|
||||
pip install -U git+https://github.com/keras-team/keras-core
|
||||
pip install -U git+https://github.com/keras-team/keras
|
||||
```
|
||||
"""
|
||||
|
||||
@ -43,9 +43,9 @@ os.environ["KERAS_BACKEND"] = "jax" # @param ["tensorflow", "jax", "torch"]
|
||||
|
||||
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
from keras_core import layers
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import layers
|
||||
from keras import ops
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
@ -58,7 +58,7 @@ for input_path, target_path in zip(input_img_paths[:10], target_img_paths[:10]):
|
||||
"""
|
||||
|
||||
from IPython.display import Image, display
|
||||
from keras_core.utils import load_img
|
||||
from keras.utils import load_img
|
||||
from PIL import ImageOps
|
||||
|
||||
# Display input image #7
|
||||
@ -72,7 +72,7 @@ display(img)
|
||||
## Prepare dataset to load & vectorize batches of data
|
||||
"""
|
||||
|
||||
import keras_core as keras
|
||||
import keras as keras
|
||||
import numpy as np
|
||||
from tensorflow import data as tf_data
|
||||
from tensorflow import image as tf_image
|
||||
@ -118,7 +118,7 @@ def get_dataset(
|
||||
## Prepare U-Net Xception-style model
|
||||
"""
|
||||
|
||||
from keras_core import layers
|
||||
from keras import layers
|
||||
|
||||
|
||||
def get_model(img_size, num_classes):
|
||||
|
@ -26,8 +26,8 @@ the class segmentation of the training inputs.
|
||||
|
||||
import random
|
||||
import numpy as np
|
||||
import keras_core as keras
|
||||
from keras_core import ops
|
||||
import keras as keras
|
||||
from keras import ops
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
"""
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user