PerceptiLabs
Search…
Custom
The Custom Component provides a generic component in which you can write custom Python (e.g., TensorFlow) code to transform data using the Component's 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:
1
class LayerCustom_LayerCustom_1Keras(tf.keras.layers.Layer, PerceptiLabsVisualizer):
2
def call(self, inputs, training=True):
3
4
raise TypeError("Missing input connection 'input'")
5
6
7
input_ = inputs['input']
8
output = preview = input_
9
10
11
self._outputs = {
12
'output': output,
13
'preview': output,
14
}
15
16
17
return self._outputs
18
19
def get_config(self):
20
"""Any variables belonging to this layer that should be rendered in the frontend.
21
22
Returns:
23
A dictionary with tensor names for keys and picklable for values.
24
"""
25
return {}
26
27
@property
28
def visualized_trainables(self):
29
""" Returns two tf.Variables (weights, biases) to be visualized in the frontend """
30
return tf.constant(0), tf.constant(0)
31
32
33
class LayerCustom_LayerCustom_1(Tf2xLayer):
34
def __init__(self):
35
super().__init__(
36
keras_class=LayerCustom_LayerCustom_1Keras
37
)
Copied!
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:
1
input_ = inputs['input']
2
3
"""add your transformation(s)/custom code here..."""
4
5
output = preview = input_
Copied!
Tip: You can include import statements above the class declarations to import other Python modules.
Last modified 2mo ago
Copy link
Contents
Default Code