标签:super from 传递 ble ken 更改 支持 back uil
需要实现三个方法:
from keras import backend as K
from keras.layers import Layer
class MyLayer(Layer):
def __init__(self, output_dim, **kwargs):
self.output_dim = output_dim
super(MyLayer, self).__init__(**kwargs)
def build(self, input_shape):
# Create a trainable weight variable for this layer.
self.kernel = self.add_weight(name=‘kernel‘,
shape=(input_shape[1], self.output_dim),
initializer=‘uniform‘,
trainable=True)
super(MyLayer, self).build(input_shape) # Be sure to call this at the end
def call(self, x):
return K.dot(x, self.kernel)
def compute_output_shape(self, input_shape):
return (input_shape[0], self.output_dim)
标签:super from 传递 ble ken 更改 支持 back uil
原文地址:https://www.cnblogs.com/zhouyu0-0/p/12204654.html