vgslify.core package

Submodules

vgslify.core.config module

class vgslify.core.config.Conv2DConfig(activation, kernel_size, strides, filters)[source]

Bases: object

activation: str
filters: int
kernel_size: tuple
strides: tuple
class vgslify.core.config.DenseConfig(activation, units)[source]

Bases: object

activation: str
units: int
class vgslify.core.config.DropoutConfig(rate)[source]

Bases: object

rate: float
class vgslify.core.config.InputConfig(batch_size, depth, height, width, channels)[source]

Bases: object

batch_size: int
channels: int
depth: int
height: int
width: int
class vgslify.core.config.Pooling2DConfig(pool_size, strides)[source]

Bases: object

pool_size: tuple
strides: tuple
class vgslify.core.config.RNNConfig(units, return_sequences, go_backwards, dropout, recurrent_dropout, rnn_type=None)[source]

Bases: object

dropout: float
go_backwards: bool
recurrent_dropout: float
return_sequences: bool
rnn_type: str = None
units: int
class vgslify.core.config.ReshapeConfig(target_shape)[source]

Bases: object

target_shape: tuple

vgslify.core.factory module

class vgslify.core.factory.LayerFactory[source]

Bases: ABC

Abstract base class for creating neural network layers from VGSL specifications. This class defines the interface that must be implemented by concrete factories for different frameworks (e.g., TensorFlow, PyTorch).

All methods are static to allow direct layer creation without instantiating the factory.

abstract static activation(spec)[source]

Create an Activation layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the Activation layer.

Returns:

The created Activation layer.

Return type:

Layer

abstract static avgpool2d(spec)[source]

Create an AvgPooling2D layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the AvgPooling2D layer.

Returns:

The created AvgPooling2D layer.

Return type:

Layer

abstract static batchnorm(spec)[source]

Create a BatchNormalization layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the BatchNormalization layer.

Returns:

The created BatchNormalization layer.

Return type:

Layer

abstract static bidirectional(spec)[source]

Create a Bidirectional RNN layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the Bidirectional RNN layer.

Returns:

The created Bidirectional RNN layer.

Return type:

Layer

abstract static build_final_model(inputs, outputs, name)[source]

Build the final model using the specified backend.

Parameters:
  • inputs (Layer) – The input layer of the model.

  • outputs (Layer) – The output layer of the model.

  • name (str) – The name of the model.

Returns:

The built model using the specified backend.

Return type:

model

abstract static conv2d(spec)[source]

Create a Conv2D layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the Conv2D layer.

Returns:

The created Conv2D layer.

Return type:

Layer

abstract static dense(spec)[source]

Create a Dense (fully connected) layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the Dense layer.

Returns:

The created Dense layer.

Return type:

Layer

abstract static dropout(spec)[source]

Create a Dropout layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the Dropout layer.

Returns:

The created Dropout layer.

Return type:

Layer

abstract static flatten(spec)[source]

Create a Flatten layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the Flatten layer.

Returns:

The created Flatten layer.

Return type:

Layer

abstract static gru(spec)[source]

Create a GRU layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the GRU layer.

Returns:

The created GRU layer.

Return type:

Layer

abstract static input(spec)[source]

Create the input layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the input layer.

Returns:

The created input layer.

Return type:

Layer

abstract static lstm(spec)[source]

Create an LSTM layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the LSTM layer.

Returns:

The created LSTM layer.

Return type:

Layer

abstract static maxpooling2d(spec)[source]

Create a MaxPooling2D layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the MaxPooling2D layer.

Returns:

The created MaxPooling2D layer.

Return type:

Layer

abstract static reshape(spec)[source]

Create a Reshape layer based on the VGSL specification string.

Parameters:

spec (str) – The VGSL specification string for the Reshape layer.

Returns:

The created Reshape layer.

Return type:

Layer

vgslify.core.parser module

vgslify.core.parser.parse_activation_spec(spec)[source]

Parses a VGSL specification string for an Activation layer and returns the activation function.

Parameters:

spec (str) – VGSL specification for the Activation layer. Expected format: A(s|t|r|l|m) - s: softmax - t: tanh - r: relu - l: linear - m: sigmoid

Returns:

The activation function name.

Return type:

str

Raises:

ValueError – If the provided VGSL spec string does not match the expected format.

Examples

>>> activation = parse_activation_spec("Ar")
>>> print(activation)
'relu'
vgslify.core.parser.parse_conv2d_spec(spec)[source]

Parses a VGSL specification string for a Conv2D layer and returns the parsed configuration.

Parameters:

spec (str) – VGSL specification for the convolutional layer. Expected format: C(s|t|r|l|m)<x>,<y>,[<s_x>,<s_y>,]<d> - (s|t|r|l|m): Activation type. - <x>,<y>: Kernel size. - <s_x>,<s_y>: Optional strides (defaults to (1, 1) if not provided). - <d>: Number of filters (depth).

Returns:

Parsed configuration for the Conv2D layer.

Return type:

Conv2DConfig

Raises:

ValueError: – If the provided VGSL spec string does not match the expected format.

Examples

>>> from vgslify.core.parser import parse_conv2d_spec
>>> config = parse_conv2d_spec("Cr3,3,64")
>>> print(config)
Conv2DConfig(activation='relu', kernel_size=(3, 3), strides=(1, 1), filters=64)
vgslify.core.parser.parse_dense_spec(spec)[source]

Parses a VGSL specification string for a Dense layer and returns the parsed configuration.

Parameters:

spec (str) –

VGSL specification for the dense layer. Expected format: F(s|t|r|l|m)<d> - (s|t|r|l|m): Non-linearity type. One of sigmoid, tanh, relu,

linear, or softmax.

  • <d>: Number of outputs (units).

Returns:

Parsed configuration for the Dense layer.

Return type:

DenseConfig

Raises:

ValueError – If the provided VGSL spec string does not match the expected format.

Examples

>>> config = parse_dense_spec("Fr64")
>>> print(config)
DenseConfig(activation='relu', units=64)
vgslify.core.parser.parse_dropout_spec(spec)[source]

Parses a VGSL specification string for a Dropout layer and returns the parsed configuration.

Parameters:

spec (str) – VGSL specification for the Dropout layer. Expected format: D<rate> where <rate> is the dropout percentage (0-100).

Returns:

Parsed configuration for the Dropout layer.

Return type:

DropoutConfig

Raises:

ValueError – If the provided VGSL spec string does not match the expected format.

Examples

>>> config = parse_dropout_spec("D50")
>>> print(config)
DropoutConfig(rate=0.5)
vgslify.core.parser.parse_input_spec(spec)[source]

Parses a VGSL specification string for an Input layer and returns the parsed configuration.

Parameters:

spec (str) – VGSL specification for the Input layer. Supported format: <batch_size>,<depth>,<height>,<width>,<channels> for 4D inputs, <batch_size>,<height>,<width>,<channels> for 3D inputs, <batch_size>,<height>,<width> for 2D inputs, <batch_size>,<width> for 1D inputs.

Returns:

Parsed configuration for the Input layer.

Return type:

InputConfig

Raises:

ValueError – If the provided VGSL spec string does not match the expected format.

vgslify.core.parser.parse_pooling2d_spec(spec)[source]

Parses a VGSL specification string for a Pooling2D layer and returns the parsed configuration.

Parameters:

spec (str) – VGSL specification for the pooling layer. Expected format: Mp<x>,<y>,<s_x>,<s_y> or Ap<x>,<y>,<s_x>,<s_y> - <x>,<y>: Pool size. - <s_x>,<s_y>: Strides.

Returns:

Parsed configuration for the Pooling2D layer.

Return type:

Pooling2DConfig

Raises:

ValueError: – If the provided VGSL spec string does not match the expected format.

Examples

>>> config = parse_pooling2d_spec("Mp2,2,2,2")
>>> print(config)
Pooling2DConfig(pool_size=(2, 2), strides=(2, 2))
vgslify.core.parser.parse_reshape_spec(spec)[source]

Parses a VGSL specification string for a Reshape layer and returns the target shape.

Parameters:

spec (str) – VGSL specification for the Reshape layer. Expected format: R<x>,<y>,<z>

Returns:

Parsed configuration for the Reshape layer.

Return type:

ReshapeConfig

Raises:

ValueError – If the provided VGSL spec string does not match the expected format.

Examples

>>> config = parse_reshape_spec("R64,64,3")
>>> print(config)
ReshapeConfig(target_shape=(64, 64, 3))
vgslify.core.parser.parse_rnn_spec(spec)[source]

Parses a VGSL specification string for an RNN layer (LSTM, GRU, Bidirectional) and returns the parsed configuration.

Parameters:

spec (str) – VGSL specification for the RNN layer. Expected format: For LSTM/GRU: L(f|r)[s]<n>[,D<rate>,Rd<rate>] For Bidirectional: B(g|l)<n>[,D<rate>,Rd<rate>]

Returns:

Parsed configuration for the RNN layer.

Return type:

RNNConfig

Raises:

ValueError – If the provided VGSL spec string does not match the expected format.

Examples

>>> config = parse_rnn_spec("Lf64,D50,Rd25")
>>> print(config)
RNNConfig(units=64, return_sequences=True, go_backwards=False, dropout=0.5,
          recurrent_dropout=0.25)
vgslify.core.parser.parse_spec(model_spec)[source]

Parse the full model spec string into a list of individual layer specs.

Parameters:

model_spec (str) – The VGSL specification string defining the model architecture.

Returns:

A list of layer specification strings.

Return type:

list

vgslify.core.utils module

vgslify.core.utils.get_activation_function(activation_char)[source]

Maps a VGSL activation character to the corresponding Keras activation function.

Parameters:

activation_char (str) – The character representing the activation function in the VGSL spec.

Returns:

The name of the Keras activation function.

Return type:

str

Raises:

ValueError – If the provided activation character is not recognized.

Examples

>>> activation = get_activation_function('r')
>>> print(activation)
'relu'

Module contents