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:
"""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
defvisualized_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
classLayerCustom_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:
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.