深度学习BiGan学习笔记,keras版

对抗生成网络Gan变体集合 keras版本
bigan(Bidirectional GAN 双向Gan)
http://link.zhihu.com/?target=https://arxiv.org/abs/1605.09782
具有生成器G,编码器encoder,判别器D
作用:
1.可以使用noise经过生成器G生成图片(这一点和GAN类似)
2.随便给一张图片,经过Encoder,再经过生气G,可以生成相似的图片(新特点)

代码位置:
https://github.com/eriklindernoren/Keras-GAN/tree/master/bigan

生成器:

def build_generator(self):
	model = Sequential()
	model.add(Dense(512, input_dim=self.latent_dim))
	model.add(LeakyReLU(alpha=0.2))
	model.add(BatchNormalization(momentum=0.8))
	model.add(Dense(512))
	model.add(LeakyReLU(alpha=0.2))
	model.add(BatchNormalization(momentum=0.8))
	model.add(Dense(np.prod(self.img_shape), activation='tanh'))
	model.add(Reshape(self.img_shape))
	model.summary()
	z = Input(shape=(self.latent_dim,))
	gen_img = model(z)
	
	return Model(z, gen_img)

编码器:

def build_encoder(self):
	model = Sequential()
	model.add(Flatten(input_shape=self.img_shape))
	model.add(Dense(512))
	model.add(LeakyReLU(alpha=0.2))
	model.add(BatchNormalization(momentum=0.8))
	model.add(Dense(512))
	model.add(LeakyReLU(alpha=0.2))
	model.add(BatchNormalization(momentum=0.8))
	model.add(Dense(self.latent_dim))
	model.summary()
	
	img = Input(shape=self.img_shape)
	z = model(img)
	
	return Model(img, z)

判别器:

def build_discriminator(self):
	z = Input(shape=(self.latent_dim, ))
	img = Input(shape=self.img_shape)
	d_in = concatenate([z, Flatten()(img)])
	
	model = Dense(1024)(d_in)
	model = LeakyReLU(alpha=0.2)(model)
	model = Dropout(0.5)(model)
	model = Dense(1024)(model)
	model = LeakyReLU(alpha=0.2)(model)
	model = Dropout(0.5)(model)
	model = Dense(1024)(model)
	model = LeakyReLU(alpha=0.2)(model)
	model = Dropout(0.5)(model)
	validity = Dense(1, activation="sigmoid")(model)
	
	return Model([z, img], validity)

训练图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值