我正在尝试将Beta变化自动编码器应用于一维数据。我已经在网上找到了代码,但是该代码用于图像数据。我在将代码适应1D时遇到问题。我收到ValueError:无法将部分已知的TensorShape转换为Tensor:(?,1024)错误,我认为这可能是由于计算损失的方式造成的?
stddev = x[1]
print('mean = ', mean)
print('stddev = ', stddev)
if self.reg == 'bvae':
# kl divergence:
latent_loss = -0.5 * K.mean(1 + stddev
- K.square(mean)
- K.exp(stddev), axis=-1)
# use beta to force less usage of vector space:
# also try to use <capacity> dimensions of the space:
print("latent_loss", latent_loss)
latent_loss = self.beta * K.abs(latent_loss - self.capacity/self.shape.as_list()[1])
print("latent_loss", latent_loss)
self.add_loss(latent_loss, x)
def Build(self):
# create the input layer for feeding the netowrk
inLayer = Input(shape=(16889,))
net = Dense(1024, activation='relu',kernel_initializer='glorot_uniform')(inLayer)
net = BatchNormalization()(net)
net = Activation('relu')(net)
mean = Dense(1024, name = 'mean')(net)
stddev = Dense(1024, name = 'std')(net)
sample = SampleLayer(self.latentConstraints, self.beta,self.latentCapacity, self.randomSample)([mean, stddev])
return Model(inputs=inLayer, outputs=sample)```