简体   繁体   English

在Keras中使用2个张量输入定义自定义层

[英]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.

相关问题 "Keras:没有输入的自定义层" - Keras: Custom layer without inputs 该层的所有输入应为张量 - All inputs to the layer should be tensors 在 Keras 中是否可以再次在以下自定义层中使用神经网络的输入? - Is it possible in Keras to use the inputs of a neural network in a following custom layer again? 如何在 Tensorflow 2.x Keras 自定义层中使用多个输入? - How to use multiple inputs in Tensorflow 2.x Keras Custom Layer? 使用 ValueError 构建自定义联合平均过程:层顺序需要 1 个输入,但它收到 3 个输入张量 - Build Custom Federated averaging process with ValueError: Layer sequential expects 1 inputs, but it received 3 input tensors 具有 TensorFlow 输入的 MNIST 应该是张量 - MNIST with TensorFlow-Inputs to a layer should be tensors 无法将数据输入自定义损失:急切执行 function 的输入不能是 Keras 符号张量 - Can't input data to custom loss: Inputs to eager execution function cannot be Keras symbolic tensors 自定义损失问题:急切执行的输入 function 不能是 keras 符号张量但找到 - Custom loss problem: inputs to eager execution function cannot be keras symbolic tensors but found 如何在其调用方法中使用 boolean 参数定义自定义 keras 层? - How to define a custom keras layer with boolean argument in it's call method? 如何定义具有多个输入张量的图层(具有不同形状的张量) - How to define a layer with multiple input tensors(tensors with different shape)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM