Skip to main content

VGSLify is a Python toolkit designed for rapid prototyping and seamless conversion between TensorFlow models and the Variable-size Graph Specification Language (VGSL). Drawing inspiration from Tesseract's VGSL specs, VGSLify introduces enhancements and provides a streamlined approach to define, train, and interpret deep learning models using VGSL.

Project description

VGSLify: Variable-size Graph Specification for TensorFlow & PyTorch

PyPI Downloads License

VGSLify simplifies defining, training, and interpreting deep learning models using the Variable-size Graph Specification Language (VGSL). Inspired by Tesseract's VGSL specs, VGSLify enhances and streamlines the process for both TensorFlow and PyTorch.

Table of Contents

Installation

pip install vgslify

Install your chosen backend:

# For TensorFlow
pip install tensorflow

# For PyTorch
pip install torch

Verify installation:

python -c "import vgslify; print(vgslify.__version__)"

How VGSL Works

VGSL uses concise strings to define model architectures. For example:

None,None,64,1 Cr3,3,32 Mp2,2 Cr3,3,64 Mp2,2 Rc3 Fr64 D20 Lrs128 D20 Lrs64 D20 Fs92

Each part represents a layer: input, convolution, pooling, reshaping, fully connected, LSTM, and output. VGSL allows specifying activation functions for customization.

Quick Start

Generating a Model with VGSLify

from vgslify.generator import VGSLModelGenerator

# Define the VGSL specification
vgsl_spec = "None,None,64,1 Cr3,3,32 Mp2,2 Fs92"

# Choose backend: "tensorflow", "torch", or "auto" (defaults to whichever is available)
vgsl_gn = VGSLModelGenerator(backend="tensorflow") 
model = vgsl_gn.generate_model(vgsl_spec, model_name="MyModel")
model.summary()


vgsl_gn = VGSLModelGenerator(backend="torch") # Switch to PyTorch
model = vgsl_gn.generate_model(vgsl_spec, model_name="MyTorchModel")
print(model)

Creating Individual Layers with VGSLify

from vgslify.generator import VGSLModelGenerator

vgsl_gn = VGSLModelGenerator(backend="tensorflow")
conv2d_layer = vgsl_gn.construct_layer("Cr3,3,64")

# Integrate into an existing model:
# model = tf.keras.Sequential()
# model.add(conv2d_layer) # ...


# Example with generate_history:
history = vgsl_gn.generate_history("None,None,64,1 Cr3,3,32 Mp2,2 Fs92")
for layer in history:
    print(layer)

Converting Models to VGSL

from vgslify.utils import model_to_spec
import tensorflow as tf
# Or import torch.nn as nn

# TensorFlow example:
model = tf.keras.models.load_model("path_to_your_model.keras") # If loading from file

# PyTorch example:
# model = MyPyTorchModel() # Assuming MyPyTorchModel is defined elsewhere


vgsl_spec_string = model_to_spec(model)
print(vgsl_spec_string)

Note: Flatten/Reshape layers might require manual input shape adjustment in the generated VGSL.

Additional Documentation

See the VGSL Documentation for more details on supported layers and their specifications.

Contributing

Contributions are welcome! Fork the repository, set up your environment, make changes, and submit a pull request. Create issues for bugs or suggestions.

License

MIT License. See LICENSE file.

Acknowledgements

Thanks to the creators and contributors of the original VGSL specification.

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

vgslify-0.13.1.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

vgslify-0.13.1-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file vgslify-0.13.1.tar.gz.

File metadata

  • Download URL: vgslify-0.13.1.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for vgslify-0.13.1.tar.gz
Algorithm Hash digest
SHA256 917e974c810cfa34b3268fd8d824d0cd8b9614305fadb457d3380b4205b7cc97
MD5 89bf15f4402dfbdc101bd4459811b830
BLAKE2b-256 1e0a835f3cf74b494669639a3c0bee89ad81a28b6bc286f34af7c1d3c649760b

See more details on using hashes here.

File details

Details for the file vgslify-0.13.1-py3-none-any.whl.

File metadata

  • Download URL: vgslify-0.13.1-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for vgslify-0.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c40ba3eb9bda9a9d9b9979327355848f4b11b662382fe5f8e6ddac3fde9e4bc5
MD5 8d22bedbc18f9af1c8e424049ce6dcf5
BLAKE2b-256 b2cf74bc16b15240f71d5ee853f6a7744c34a2768a6894b74168638fcab3c55d

See more details on using hashes here.

Supported by

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