CyxWiz LogoCyxWiz
DocsCode Generation

Code Generation

Export your visual model to production-ready Python code in multiple frameworks.

Supported Frameworks

FrameworkOutputBest For
PyTorchtorch.nn.ModuleResearch, flexibility
TensorFlowtf.keras.ModelProduction, deployment
Keraskeras.ModelSimplicity, readability
PyCyxWizpycyxwiz.SequentialCyxWiz native training

Generating Code

Toolbar Buttons
Click the framework button in the Node Editor toolbar:
[Save] [Load] [PyTorch] [TensorFlow] [Keras] [Validate]
Nodes Menu
Nodes > Generate Code > [Framework]
Context Menu
Right-click on canvas > Generate Code > [Framework]
Output Location
Generated code is automatically inserted into the Script Editor.

PyTorch Output

import torch
import torch.nn as nn

class CyxWizModel(nn.Module):
    def __init__(self):
        super(CyxWizModel, self).__init__()
        self.dense_0 = nn.Linear(784, 128)
        self.relu_1 = nn.ReLU()
        self.dense_2 = nn.Linear(128, 64)
        self.relu_3 = nn.ReLU()
        self.dense_4 = nn.Linear(64, 10)
        self.softmax_5 = nn.Softmax(dim=1)

    def forward(self, x):
        x = self.dense_0(x)
        x = self.relu_1(x)
        x = self.dense_2(x)
        x = self.relu_3(x)
        x = self.dense_4(x)
        x = self.softmax_5(x)
        return x

# Instantiate model
model = CyxWizModel()

# Loss and optimizer
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

TensorFlow Output

import tensorflow as tf
from tensorflow.keras import layers, Model

class CyxWizModel(Model):
    def __init__(self):
        super(CyxWizModel, self).__init__()
        self.dense_0 = layers.Dense(128, activation=None)
        self.relu_1 = layers.ReLU()
        self.dense_2 = layers.Dense(64, activation=None)
        self.relu_3 = layers.ReLU()
        self.dense_4 = layers.Dense(10, activation=None)
        self.softmax_5 = layers.Softmax()

    def call(self, x, training=False):
        x = self.dense_0(x)
        x = self.relu_1(x)
        x = self.dense_2(x)
        x = self.relu_3(x)
        x = self.dense_4(x)
        x = self.softmax_5(x)
        return x

# Instantiate and compile
model = CyxWizModel()
model.compile(
    optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
    loss=tf.keras.losses.SparseCategoricalCrossentropy(),
    metrics=['accuracy']
)

Keras Output

Sequential API
import keras
from keras import layers

model = keras.Sequential([
    layers.Dense(128,
        activation='relu',
        input_shape=(784,)),
    layers.Dense(64, activation='relu'),
    layers.Dense(10, activation='softmax'),
])

model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)
Functional API
import keras
from keras import layers

inputs = keras.Input(shape=(784,))
x = layers.Dense(128)(inputs)
x = layers.ReLU()(x)
x = layers.Dense(64)(x)
x = layers.ReLU()(x)
outputs = layers.Dense(10,
    activation='softmax')(x)

model = keras.Model(
    inputs=inputs,
    outputs=outputs
)

PyCyxWiz Output

import pycyxwiz as cyx

# Initialize backend
cyx.initialize()

# Build model
model = cyx.Sequential()
model.add(cyx.Dense(128, activation='relu'))
model.add(cyx.Dense(64, activation='relu'))
model.add(cyx.Dense(10, activation='softmax'))

# Configure training
model.compile(
    optimizer=cyx.Adam(lr=0.001),
    loss=cyx.CrossEntropyLoss(),
    metrics=['accuracy']
)

# Train
model.fit(
    x_train, y_train,
    epochs=10,
    batch_size=32,
    validation_data=(x_val, y_val)
)

Handling Skip Connections

PyTorch
def forward(self, x):
    identity = x
    x = self.conv(x)
    x = self.bn(x)
    x = x + identity  # Residual
    x = self.relu(x)
    return x
TensorFlow/Keras
identity = x
x = conv(x)
x = bn(x)
x = layers.Add()([x, identity])
x = layers.ReLU()(x)

Validation Before Generation

The code generator validates the graph:

  1. Has Input - DatasetInput node present
  2. Has Output - Output node present
  3. No Cycles - Acyclic graph
  4. All Connected - No orphan nodes
  5. Type Compatibility - Pin types match

Naming Convention

Node TypeNaming PatternExample
Layers{type}_{index}dense_0, conv_1
Custom namesUser-specifiedPreserved
Skip connectionsidentity_{index}identity_0

Tips

  1. Validate First - Fix errors before generating
  2. Review Output - Check generated code for correctness
  3. Test Generated Code - Run to verify functionality
  4. Customize as Needed - Generated code is a starting point
  5. Keep Graph Simple - Complex graphs = complex code

Exporting to File

From Script Editor
  1. Generate code to Script Editor
  2. File > Save As
  3. Choose .py extension
Direct Export

Nodes > Export Code to File

Saves to file with framework in filename:

  • model_pytorch.py
  • model_tensorflow.py
  • model_keras.py