自定义Keras Layer

Posted mstk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义Keras Layer相关的知识,希望对你有一定的参考价值。

Keras的Layer其实就是一个Class, 要具有以下几个方法:

(1) build(input_shape): 定义权重的地方, 如果不需要定义权重, 也要有self.built = True;

(2) call(x): 编写功能逻辑的地方, 实现Layer的功能逻辑;

(3) compute_output_shape(input_shape): 根据input_shape, 计算形状变化的地方, 能够让Keras推断输出的Tensor的Shape.

 

以上是关于自定义Keras Layer的主要内容,如果未能解决你的问题,请参考以下文章