【发布时间】:2018-06-29 10:24:15
【问题描述】:
我正在尝试在 keras 中创建我自己的图层,但我得到了错误。我的简单代码如下:
class MyLayer(Layer):
def __init__(self, output_dim, **kwargs):
self.output_dim = output_dim
self.updates = []
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 somewhere!
def call(self, x):
return K.dot(x, self.kernel)
def compute_output_shape(self, input_shape):
return (input_shape[0], self.output_dim)
错误是:
AttributeError Traceback(最近一次调用最后一次) 在 () ----> 1 MyLayer(output_dim=10)
in init(self, output_dim, **kwargs)
8 self.output_dim = output_dim
9
---> 10 个 self.updates = []
11
12 super(MyLayer, self).init(**kwargs)
AttributeError: 无法设置属性
你能帮忙解决这个问题吗? 谢谢
【问题讨论】: