访问 Keras 中自定义层内的目标

Dal*_*eme 6 python keras keras-layer

我正在 Keras 中编写一个自定义层,我想知道是否有一种方法可以访问层内的目标值。

class Custom(Layer):
    def __init__(self, **kwargs):
        super(Custom, self).__init__(**kwargs)

    def build(self, input_shape):
        super(Custom, self).build(input_shape) 

    def call(self, x):
        result =  K.dot(x, self.kernel)
    targets = ???
        return result

    def compute_output_shape(self, input_shape):
        return (input_shape[0], self.output_dim)
Run Code Online (Sandbox Code Playgroud)

现在,我之前所做的是使用占位符在每个批次开始时存储和更新目标值。但现在我正在使用生成器,似乎在生成器内我无法调用 Keras 的 set_value 函数,因此我无法更新我的“目标占位符”

有没有什么巧妙的方法来访问自定义层中的目标值?