vgslify.torch package

Submodules

vgslify.torch.layers module

class vgslify.torch.layers.TorchLayerFactory(input_shape=None)[source]

Bases: LayerFactory

TorchLayerFactory is responsible for creating PyTorch-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 PyTorch 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 PyTorch model.

Return type:

torch.nn.Module

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

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

class vgslify.torch.reshape.Reshape(*args: Any, **kwargs: Any)[source]

Bases: Module

Custom PyTorch Reshape layer. To be used in the VGSL spec.

forward(x)[source]

Forward pass for reshaping the input tensor.

Parameters:

x (torch.Tensor) – Input tensor to reshape.

Returns:

Reshaped tensor.

Return type:

torch.Tensor

Module contents