【发布时间】:2019-06-08 21:17:12
【问题描述】:
我想要创建乘以 X.T * X 的多项式特征的层:
class QuadraticLayer(Layer):
def __init__(self, **kwargs):
super(QuadraticLayer, self).__init__(**kwargs)
def build(self, input_shape):
assert isinstance(input_shape, tuple)
print(input_shape)
self.in_shape = input_shape[1]
self.out_shape = input_shape[1] ** 2
super(QuadraticLayer, self).build(input_shape) # Be sure to call this at the end
def call(self, x):
print(x.shape)
tf.reshape(x, (self.in_shape, 1, -1), name=None)
x = tf.matmul(x, x, transpose_a=True)
return tf.reshape(x, (-1, self.out_shape))
def compute_output_shape(self, input_shape):
return (None, self.out_shape)
我的问题是 call 张量 x 是一个批量张量 - 如何编写适用于每个训练示例的层而不是处理整个批量张量?
【问题讨论】:
标签: tensorflow machine-learning keras keras-layer