[英]Define a custom layer with 2 tensors inputs in Keras
I would like to implement a custom layer. 我想实现一个自定义层。 The 2 inputs of my custom layer are 2 tensors, which come from 2 seperate 2D convolution layers, is there an example?
我的自定义层的2个输入是2个张量,它们来自2个单独的2D卷积层,有一个例子吗?
Since you don't need it to be trainable, a lambda function will also do. 由于您不需要训练它,因此lambda函数也可以。 Or you can keep the custom layer as you have it, and set trainable to False.
或者,您可以保留自定义图层,并将其设置为False。 The weights will never be updated for this layer, and whatever you do here will forward propagate to the next layer in the model and as mentioned in the comments, backprop will impact the other layers with weights.
权重将永远不会针对该层进行更新,并且您在此处所做的任何操作都将向前传播到模型中的下一层,并且如注释中所述,反向传播将通过权重影响其他层。 So, definitely your model will learn something.
因此,您的模型肯定会学到一些东西。
I personally recommend using a custom layer, if you decide later to add some learning to this layer and check your results. 我个人建议使用自定义层,如果您稍后决定向该层添加一些知识并检查结果。 You cannot do this in a Lambda function.
您不能在Lambda函数中执行此操作。 If you add one (kernel), you will have to use in the 'call' method.
如果添加一个(内核),则必须在“调用”方法中使用。 Your model will throw an error during training otherwise.
否则,您的模型将在训练过程中引发错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.