vgslify.tensorflow package

Submodules

vgslify.tensorflow.layers module

class vgslify.tensorflow.layers.TensorFlowLayerFactory(input_shape=None)[source]

Bases: LayerFactory

TensorFlowLayerFactory is responsible for creating TensorFlow-specific layers based on parsed VGSL (Variable-size Graph Specification Language) specifications.

This factory handles the creation of various types of layers, including convolutional layers, pooling layers, RNN layers, dense layers, activation layers, and more.

layers

A list of TensorFlow layers that have been added to the factory.

Type:

list

shape

The current shape of the tensor, excluding the batch size.

Type:

tuple of int

_input_shape

The original input shape provided during initialization.

Type:

tuple of int or None

build(name='VGSL_Model')[source]

Build the final model using the accumulated layers.

Parameters:

name (str, optional) – The name of the model, by default “VGSL_Model”

Returns:

The constructed TensorFlow model.

Return type:

tf.keras.models.Model

Raises:
  • ValueError – If no layers have been added to the model.

  • ValueError – If no input shape has been specified for the model.

classmethod get_custom_layer_registry()[source]

Return the dict of all registered custom layers for this factory class.

classmethod register(prefix, builder_fn)[source]

Register a custom layer builder function under a given spec prefix.

Parameters:
  • prefix (str) – The VGSL spec prefix that triggers this custom layer (e.g. “Xsw”).

  • builder_fn (callable) – A function with signature builder_fn(self, spec: str) -> layer that, given the VGSL spec string, returns the framework-specific layer.

vgslify.tensorflow.layers.register_custom_layer(prefix)[source]

Decorator to register a custom layer builder function for TensorFlowLayerFactory.

This allows users to easily extend TensorFlowLayerFactory with custom layer types by defining a function that constructs a TensorFlow layer from a VGSL spec string.

Parameters:

prefix (str) – The VGSL spec prefix that triggers this custom layer (e.g. “Xsw”).

Returns:

A decorator that registers the provided function as a builder for the given prefix.

Return type:

Callable

Raises:

ValueError – If a builder for the prefix is already registered or if the function signature is invalid.

Examples

>>> from vgslify.tensorflow.layers import register_custom_layer
>>> @register_custom_layer("Xsw")
... def build_custom_layer(factory, spec):
...     # Custom layer building logic
...     return tf.keras.layers.Dense(10)

Module contents

class vgslify.tensorflow.TensorFlowLayerFactory(input_shape=None)[source]

Bases: LayerFactory

TensorFlowLayerFactory is responsible for creating TensorFlow-specific layers based on parsed VGSL (Variable-size Graph Specification Language) specifications.

This factory handles the creation of various types of layers, including convolutional layers, pooling layers, RNN layers, dense layers, activation layers, and more.

layers

A list of TensorFlow layers that have been added to the factory.

Type:

list

shape

The current shape of the tensor, excluding the batch size.

Type:

tuple of int

_input_shape

The original input shape provided during initialization.

Type:

tuple of int or None

build(name='VGSL_Model')[source]

Build the final model using the accumulated layers.

Parameters:

name (str, optional) – The name of the model, by default “VGSL_Model”

Returns:

The constructed TensorFlow model.

Return type:

tf.keras.models.Model

Raises:
  • ValueError – If no layers have been added to the model.

  • ValueError – If no input shape has been specified for the model.

classmethod get_custom_layer_registry()[source]

Return the dict of all registered custom layers for this factory class.

classmethod register(prefix, builder_fn)[source]

Register a custom layer builder function under a given spec prefix.

Parameters:
  • prefix (str) – The VGSL spec prefix that triggers this custom layer (e.g. “Xsw”).

  • builder_fn (callable) – A function with signature builder_fn(self, spec: str) -> layer that, given the VGSL spec string, returns the framework-specific layer.

vgslify.tensorflow.register_custom_layer(prefix)[source]

Decorator to register a custom layer builder function for TensorFlowLayerFactory.

This allows users to easily extend TensorFlowLayerFactory with custom layer types by defining a function that constructs a TensorFlow layer from a VGSL spec string.

Parameters:

prefix (str) – The VGSL spec prefix that triggers this custom layer (e.g. “Xsw”).

Returns:

A decorator that registers the provided function as a builder for the given prefix.

Return type:

Callable

Raises:

ValueError – If a builder for the prefix is already registered or if the function signature is invalid.

Examples

>>> from vgslify.tensorflow.layers import register_custom_layer
>>> @register_custom_layer("Xsw")
... def build_custom_layer(factory, spec):
...     # Custom layer building logic
...     return tf.keras.layers.Dense(10)