Multi-backend deep learning framework providing a unified API for building and training neural networks across JAX, TensorFlow, PyTorch, and OpenVINO backends
npx @tessl/cli install tessl/pypi-keras-nightly@3.11.0A multi-backend deep learning framework that provides a unified API for building and training neural networks across JAX, TensorFlow, PyTorch, and OpenVINO backends. Keras 3 is designed for accelerated model development with high-level abstractions while maintaining state-of-the-art performance through backend-specific optimizations.
pip install keras-nightlyimport kerasCommon imports for building neural networks:
from keras import layers, models, optimizers, losses, metrics
from keras.models import Sequential, Model
from keras.layers import Dense, Conv2D, LSTMimport keras
from keras import layers
# Create a simple sequential model
model = keras.Sequential([
layers.Dense(64, activation='relu', input_shape=(784,)),
layers.Dropout(0.2),
layers.Dense(10, activation='softmax')
])
# Compile the model
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
# Train the model
model.fit(x_train, y_train, epochs=5, validation_split=0.2)
# Make predictions
predictions = model.predict(x_test)Keras provides a layered architecture enabling flexible neural network construction:
This design allows every component to be customized while providing seamless model portability across different backends (JAX, TensorFlow, PyTorch, OpenVINO) without code changes.
Essential classes for building and training neural networks, including model containers, base layer classes, and core data structures.
class Sequential:
def __init__(self, layers=None, name=None): ...
def add(self, layer): ...
def compile(self, optimizer, loss=None, metrics=None, **kwargs): ...
def fit(self, x, y=None, **kwargs): ...
class Model:
def __init__(self, inputs, outputs, name=None): ...
def compile(self, optimizer, loss=None, metrics=None, **kwargs): ...
def fit(self, x, y=None, **kwargs): ...
class Layer:
def __init__(self, **kwargs): ...
def call(self, inputs, **kwargs): ...
def build(self, input_shape): ...
def Input(shape, batch_size=None, name=None, dtype=None, **kwargs): ...Complete collection of neural network layer types including dense, convolutional, recurrent, normalization, attention, and preprocessing layers.
class Dense:
def __init__(self, units, activation=None, use_bias=True, **kwargs): ...
class Conv2D:
def __init__(self, filters, kernel_size, strides=(1,1), padding='valid', **kwargs): ...
class LSTM:
def __init__(self, units, activation='tanh', return_sequences=False, **kwargs): ...
class BatchNormalization:
def __init__(self, axis=-1, momentum=0.99, epsilon=1e-3, **kwargs): ...
class MultiHeadAttention:
def __init__(self, num_heads, key_dim, **kwargs): ...Comprehensive collection of loss functions for training and metrics for evaluation across classification, regression, and specialized tasks.
class BinaryCrossentropy:
def __init__(self, from_logits=False, **kwargs): ...
class SparseCategoricalCrossentropy:
def __init__(self, from_logits=False, **kwargs): ...
class MeanSquaredError:
def __init__(self, **kwargs): ...
class Accuracy:
def __init__(self, name='accuracy', **kwargs): ...
class F1Score:
def __init__(self, average=None, threshold=None, **kwargs): ...Optimization algorithms for training neural networks, from basic gradient descent to advanced adaptive methods.
class Adam:
def __init__(self, learning_rate=0.001, beta_1=0.9, beta_2=0.999, **kwargs): ...
class SGD:
def __init__(self, learning_rate=0.01, momentum=0.0, nesterov=False, **kwargs): ...
class AdamW:
def __init__(self, learning_rate=0.001, weight_decay=0.004, **kwargs): ...
class RMSprop:
def __init__(self, learning_rate=0.001, rho=0.9, **kwargs): ...Extensive collection of pre-trained computer vision models with ImageNet weights for transfer learning and feature extraction.
def ResNet50(include_top=True, weights='imagenet', input_tensor=None, **kwargs): ...
def EfficientNetB0(include_top=True, weights='imagenet', **kwargs): ...
def VGG16(include_top=True, weights='imagenet', **kwargs): ...
def MobileNetV2(include_top=True, weights='imagenet', **kwargs): ...
def InceptionV3(include_top=True, weights='imagenet', **kwargs): ...Backend-agnostic mathematical operations providing NumPy-compatible APIs and neural network specific functions.
# Core operations
def cast(x, dtype): ...
def convert_to_tensor(x, dtype=None): ...
def shape(x): ...
def dtype(x): ...
# Mathematical functions
def add(x1, x2): ...
def matmul(x1, x2): ...
def softmax(x, axis=-1): ...
def relu(x): ...
# Neural network operations
def conv(inputs, kernel, strides=1, padding='valid', **kwargs): ...
def batch_normalization(x, mean, variance, offset, scale, **kwargs): ...Comprehensive data preprocessing utilities for images, text, audio, and numerical data with built-in augmentation capabilities.
class TextVectorization:
def __init__(self, max_tokens=None, **kwargs): ...
class Normalization:
def __init__(self, axis=-1, **kwargs): ...
class RandomRotation:
def __init__(self, factor, **kwargs): ...
def image_dataset_from_directory(directory, labels='inferred', **kwargs): ...
def text_dataset_from_directory(directory, labels='inferred', **kwargs): ...Training utilities, callbacks for monitoring and controlling training, and model persistence functionality.
class EarlyStopping:
def __init__(self, monitor='val_loss', patience=0, **kwargs): ...
class ModelCheckpoint:
def __init__(self, filepath, monitor='val_loss', **kwargs): ...
class ReduceLROnPlateau:
def __init__(self, monitor='val_loss', factor=0.1, patience=10, **kwargs): ...
def save_model(model, filepath, overwrite=True, **kwargs): ...
def load_model(filepath, custom_objects=None, compile=True, **kwargs): ...Backend configuration utilities for managing numerical precision, data formats, and cross-backend compatibility.
def backend(): ...
def set_floatx(dtype): ...
def set_image_data_format(data_format): ...
def clear_session(): ...
def set_random_seed(seed): ...Comprehensive collection of activation functions for neural networks, from traditional ReLU and sigmoid to modern alternatives like GELU and Swish.
def relu(x, negative_slope=0.0, max_value=None, threshold=0.0): ...
def sigmoid(x): ...
def tanh(x): ...
def softmax(x, axis=-1): ...
def gelu(x, approximate=False): ...
def silu(x): ...
def mish(x): ...
def elu(x, alpha=1.0): ...
def leaky_relu(x, negative_slope=0.3): ...Weight initialization strategies for neural network layers, including constant, random, and variance-scaling methods.
class Zeros: ...
class Ones: ...
class Constant:
def __init__(self, value=0.0): ...
class RandomNormal:
def __init__(self, mean=0.0, stddev=0.05, seed=None): ...
class GlorotUniform:
def __init__(self, seed=None): ...
class HeNormal:
def __init__(self, seed=None): ...Regularization techniques for preventing overfitting, including L1, L2, and orthogonal regularization.
class L1:
def __init__(self, l1=0.01): ...
class L2:
def __init__(self, l2=0.01): ...
class L1L2:
def __init__(self, l1=0.0, l2=0.0): ...
class OrthogonalRegularizer:
def __init__(self, factor=0.01, mode='rows'): ...# Core tensor type
class KerasTensor:
shape: tuple
dtype: str
# Variable for trainable parameters
class Variable:
def __init__(self, initializer, shape=None, dtype=None, **kwargs): ...
def assign(self, value): ...
# Base types for extensibility
class Optimizer: ...
class Loss: ...
class Metric: ...
class Layer: ...
class Initializer: ...
class Regularizer: ...
class Constraint: ...
class Callback: ...