Multi-backend deep learning framework that provides a unified, high-level API for building and training neural networks across JAX, TensorFlow, PyTorch, and OpenVINO backends.
npx @tessl/cli install tessl/pypi-keras@3.11.0Keras is a multi-backend deep learning framework that provides a unified, high-level API for building and training neural networks across JAX, TensorFlow, PyTorch, and OpenVINO backends. It enables accelerated model development through its intuitive interface while offering state-of-the-art performance with backend-specific optimizations.
pip install kerasimport kerasFor specific functionality:
from keras import layers, models, optimizers, losses, metrics
from keras.applications import ResNet50, VGG16, MobileNet
from keras.datasets import mnist, cifar10import keras
from keras import layers
# Create a simple sequential model
model = keras.Sequential([
layers.Dense(128, 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_data=(x_test, y_test))Keras follows a modular architecture with these core components:
Core model types and architecture patterns for building neural networks, including Sequential models, Functional API, and Model subclassing approaches.
class Model:
def __init__(self, inputs=None, outputs=None, name=None): ...
def compile(self, optimizer='rmsprop', loss=None, metrics=None, **kwargs): ...
def fit(self, x=None, y=None, batch_size=None, epochs=1, **kwargs): ...
def predict(self, x, batch_size=None, **kwargs): ...
class Sequential(Model):
def __init__(self, layers=None, name=None): ...
def add(self, layer): ...
def Input(shape=None, batch_size=None, name=None, dtype=None, **kwargs): ...Comprehensive layer types for building neural networks, including core layers, convolutional layers, recurrent layers, attention mechanisms, normalization, pooling, and preprocessing layers.
class Layer:
def __init__(self, **kwargs): ...
def call(self, inputs, **kwargs): ...
def build(self, input_shape): ...
class Dense(Layer):
def __init__(self, units, activation=None, use_bias=True, **kwargs): ...
class Conv2D(Layer):
def __init__(self, filters, kernel_size, strides=(1, 1), padding='valid', **kwargs): ...
class LSTM(Layer):
def __init__(self, units, activation='tanh', return_sequences=False, **kwargs): ...Optimizers, losses, metrics, and callbacks for training neural networks effectively with various algorithms and monitoring tools.
class Optimizer:
def __init__(self, learning_rate=0.001, **kwargs): ...
class Adam(Optimizer):
def __init__(self, learning_rate=0.001, beta_1=0.9, beta_2=0.999, **kwargs): ...
class Loss:
def __call__(self, y_true, y_pred): ...
class SparseCategoricalCrossentropy(Loss):
def __init__(self, from_logits=False, **kwargs): ...
class Metric:
def update_state(self, y_true, y_pred): ...
def result(self): ...Ready-to-use pre-trained models for computer vision tasks, including VGG, ResNet, MobileNet, EfficientNet, and many others, with ImageNet weights.
def ResNet50(include_top=True, weights='imagenet', input_tensor=None, **kwargs): ...
def VGG16(include_top=True, weights='imagenet', input_tensor=None, **kwargs): ...
def MobileNet(include_top=True, weights='imagenet', input_tensor=None, **kwargs): ...
def EfficientNetB0(include_top=True, weights='imagenet', input_tensor=None, **kwargs): ...Built-in datasets, data preprocessing utilities, image processing functions, and various helper utilities for machine learning workflows.
# Datasets
def load_data(): ... # Available in mnist, cifar10, cifar100, fashion_mnist, etc.
# Image utilities
def load_img(path, color_mode='rgb', target_size=None, **kwargs): ...
def img_to_array(img, dtype=None): ...
def array_to_img(x, scale=True): ...
# Data utilities
def to_categorical(y, num_classes=None, dtype='float32'): ...
def normalize(x, axis=-1, order=2): ...Comprehensive set of activation functions for introducing non-linearity in neural networks, including standard activations (ReLU, sigmoid, tanh), advanced functions (GELU, Swish, Mish), and specialized activations.
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 leaky_relu(x, negative_slope=0.01): ...Complete functionality for model persistence, weight management, custom object registration, and serialization utilities for saving and loading models across different formats.
def save_model(model, filepath, overwrite=True, save_format=None, **kwargs): ...
def load_model(filepath, custom_objects=None, compile=True, safe_mode=True): ...
def save_weights(model, filepath, overwrite=True, save_format=None, **kwargs): ...
def load_weights(model, filepath, skip_mismatch=False, by_name=False, **kwargs): ...
def register_keras_serializable(package='Custom', name=None): ...Model Saving and Serialization
Weight initialization strategies for proper model initialization, including constant initializers, random initializers, and variance scaling methods optimized for different activation functions.
class Initializer: ...
class Zeros(Initializer): ...
class Ones(Initializer): ...
class GlorotNormal(Initializer): ...
class GlorotUniform(Initializer): ...
class HeNormal(Initializer): ...
class HeUniform(Initializer): ...
class Orthogonal(Initializer): ...Regularization techniques to prevent overfitting through weight penalties, including L1, L2, combined L1L2, and orthogonal regularization for improved model generalization.
class Regularizer: ...
class L1(Regularizer): ...
class L2(Regularizer): ...
class L1L2(Regularizer): ...
class OrthogonalRegularizer(Regularizer): ...
def l1(l1=0.01): ...
def l2(l2=0.01): ...Random number generation and sampling functions for various probability distributions, data augmentation, and stochastic operations with seed management for reproducibility.
def normal(shape, mean=0.0, stddev=1.0, dtype=None, seed=None): ...
def uniform(shape, minval=0.0, maxval=1.0, dtype=None, seed=None): ...
def randint(shape, minval, maxval, dtype='int32', seed=None): ...
def dropout(x, rate, noise_shape=None, seed=None): ...
def shuffle(x, axis=0, seed=None): ...
class SeedGenerator: ...Low-level operations and backend functionality for tensor operations, mathematical functions, and neural network primitives across different backend engines.
# Core operations
def cast(x, dtype): ...
def shape(x): ...
def reshape(x, shape): ...
def transpose(x, axes=None): ...
# Math operations
def add(x1, x2): ...
def multiply(x1, x2): ...
def matmul(x1, x2): ...
def relu(x): ...
def softmax(x, axis=-1): ...class KerasTensor:
"""Symbolic tensor representation used in Keras functional API."""
def __init__(self, type_spec, name=None): ...
class Variable:
"""Keras variable for storing mutable state."""
def __init__(self, initializer, shape=None, dtype=None, **kwargs): ...
def assign(self, value): ...
class DTypePolicy:
"""Policy for dtype handling in mixed precision training."""
def __init__(self, name): ...