Skip to main content

Keras Extensions for Keras3

Project description

Keras Extensions

This package offers a wide range of extensions and tools for the Keras3 framework. Please note that this package is still in development. While all methods have a comprehensive docstring, there is no API documentation yet.

The implementation of all layers, blocks and models aligns with official Keras3 layer implementations, and subclass either keras.layers.Layer or keras.models.Model. All layers are fully serializable and can be used in model.save().

Installation

The package is hosted on pypi.org and can be installed using pip

$ pip install kerex

which automatically installs keras>3.0.0. Additionally, you can use the installer with options

$ pip install kerex[jax]

which installs jax and jaxlib packages, or

$ pip install kerex[tensorflow]

which installs the tensorflow backend.

Contents

Layers

The module kerex.layers implements a wide variety of additional layers for Keras3.

Fourier Neural Operator

The first class of layers are Fourier Neural Operators (FNO), cf. Zongyi et al. (2021). The FNO layer has two parallel paths. The first path applies a spectral convolution, where the input is transformed to Fourier space, truncated to the lowest $m$ modes, multiplied by the weights, padded and then transformed back to space (or time) domain. The second path applies a $1\times1$ convolution to learn higher order dynamics.

>>> from keras import ops
>>> from kerex.layers import FNO1D
>>> fno_layer = FNO1D(filters=8, modes=8)
>>> fno_layer.build(input_shape=(None, 32, 3))
>>> x = ops.ones((1, 32, 3))
>>> y = fno_layer(x)
>>> y.shape
(1, 32, 8)

Note

The Keras3 framework does not have a complex data type. Therefore, the implementation of the spectral convolution treats the real- and imaginary parts of the weights and the inputs as two separate tensors. The multiplication of the complex weights with the complex inputs

$$wx = (w_{\text{real}} + i w_{\text{imag}})(x_{\text{real}} + i x_{\text{imag}})$$

is therefore explicitly performed as

$$y_{\text{real}} = w_{\text{real}}x_{\text{real}} - w_{\text{imag}}x_{\text{imag}}$$

and

$$y_{\text{imag}} = w_{\text{real}}x_{\text{imag}} + w_{\text{imag}}x_{\text{real}}$$

Moreover, the Tensorflow implementation requires a custom_gradient function as the automatic differentiation has trouble propagating throught the layer.

Merge layer

This module implements additional merge layer, that are not implemented in Keras3 by default.

Wrapper

This module implements wrapper, which can be used to augment any Keras3 layer with additional functionality.

Blocks

This module implements larger blocks from layers. All blocks subclass keras.layers.Layer and are serializable using model.save().

Attention

...

Autoencoder

...

TSMixer

...

Models

Autoencoder

...

Neural Operator

...

TSMixer

...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kerex-1.1.4.tar.gz (80.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kerex-1.1.4-py3-none-any.whl (118.9 kB view details)

Uploaded Python 3

File details

Details for the file kerex-1.1.4.tar.gz.

File metadata

  • Download URL: kerex-1.1.4.tar.gz
  • Upload date:
  • Size: 80.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kerex-1.1.4.tar.gz
Algorithm Hash digest
SHA256 68f633d85a20d9f61589707f8443673b9fba75ea87da909d39ac7f0e66e60292
MD5 f98bba6ce9f56655ed623bec45e6f636
BLAKE2b-256 87a82a3cd0c908bd2d7c1376ef2012dbe5054836751a21fa94fc8af96561adca

See more details on using hashes here.

File details

Details for the file kerex-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: kerex-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 118.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kerex-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c09e81edbe6957ba1d6590839b93acdb3a902b4d1e64c724222dd2c2d19d8eaf
MD5 8e7f7f5a75f2bd31a03ffacd90bdf08b
BLAKE2b-256 83e29857bd814168425f48b9aaee9cd113bc02050f6e32d70b8109de8bb3dcf9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page