【发布时间】:2019-05-07 23:49:52
【问题描述】:
我尝试编写一个自定义 keras 层,它会更改张量的值。但是,numpy 语法不起作用。我认为代码是不言自明的:
class myLayer(Layer):
def __init__(self, **kwargs):
super(myLayer, self).__init__(**kwargs)
def build(self, input_shapes):
super(myLayer, self).build(input_shapes)
def call(self, inputs, mask=None):
inputs[(inputs>0) & (inputs<1)] = 1
inputs[inputs<=0] = K.exp(inputs)
inputs[inputs>1] = K.exp(1-inputs)
return inputs
def compute_output_shape(self, input_shapes):
return input_shapes
如何用 tensorflow 写作业并且仍然允许反向传播?
【问题讨论】:
-
有关更多背景信息,我尝试实现在openreview.net/pdf/90f0e675457dac151517a5ed5c0f15d856366494.pdf 中解释的 REG-GAN,其中定义了 Kernel-Function。
标签: python tensorflow keras