The Custom Component provides a generic Component in which you can write custom Python (e.g., TensorFlow) code to transform data. This is done by using the Code Editor.
The Component's input socket must be connected to another Component that provides input data, and the output socket must be connected to another Component to output the transformed data to.

Default Code

The Custom component starts out with the following code:
class LayerCustom_LayerCustom_1Keras(tf.keras.layers.Layer, PerceptiLabsVisualizer):
def call(self, inputs, training=True):
raise TypeError("Missing input connection 'input'")
input_ = inputs['input']
output = preview = input_
self._outputs = {
'output': output,
'preview': output,
return self._outputs
def get_config(self):
"""Any variables belonging to this layer that should be rendered in the frontend.
A dictionary with tensor names for keys and picklable for values.
return {}
def visualized_trainables(self):
""" Returns two tf.Variables (weights, biases) to be visualized in the frontend """
return tf.constant(0), tf.constant(0)
class LayerCustom_LayerCustom_1(Tf2xLayer):
def __init__(self):
Note: When you connect the input socket of your Custom Component to the output socket of another Component, PerceptiLabs will automatically remove the line:
raise TypeError("Missing input connection 'input'").
You will add your code to the call() method of the LayerCustom_LayerCustom_1Keras class which is invoked by PerceptiLabs to transform data when the model runs (including when PerceptiLabs runs the model as you edit it in the Modeling Tool to display previews). In general, you will add your transformation(s) between the input and output assignments:
input_ = inputs['input']
"""add your transformation(s)/custom code here..."""
output = preview = input_
Tip: You can include import statements above the class declarations to import other Python modules.
For additional information see: How PerceptiLabs Works with TensorFlow.
Copy link