im试图创建自己的图层,该图层接受图层的输入并根据该输入图层的权重计算一些内容。 问题是,我得到的输入是张量,而张量不保存先前操作的权重。
class VarWeightPropagation(Layer):
def __init__(self,
input_layer_name='Conv2D',
**kwargs):
'''
Arguments:
'''
self.input_name = input_layer_name
super(VarWeightPropagation, self).__init__(**kwargs)
def build(self, input_shape):
#self.input_spec = [InputSpec(shape=input_shape[0])]
super(VarWeightPropagation, self).build(input_shape)
def call(self, x, mask=None):
error = x[0]
x = x[1]
if self.input_name == 'Dense':
# do some calculation based on the weight of the previous layer
else:
weights = x.get_weights()[0] # this is the main problem as tensors dont have get_weight()
# also do some calculations based on that weights
return (x,error)
def compute_output_shape(self, input_shape):
return (input_shape[0], self.output_dim)
是否有一种方法可以在我创建的自定义中使用上一层的权重? (该层仅在网络的推理状态下处于活动状态) 预先谢谢你!