-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
seperated network architectures from gan types. updated loading and p…
…lotting
- Loading branch information
Showing
8 changed files
with
309 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from libs.architectures import dense, conv1, conv2, resnet | ||
|
||
def build_generator(architecture, latent_dim, img_shape): | ||
if (architecture == 'dense'): | ||
return dense.generator(latent_dim, img_shape) | ||
if (architecture == 'conv1'): | ||
return conv1.generator(latent_dim, img_shape) | ||
if (architecture == 'conv2'): | ||
return conv2.generator(latent_dim, img_shape) | ||
if (architecture == 'resnet'): | ||
return resnet.generator(latent_dim, img_shape) | ||
|
||
def build_discriminator(architecture, img_shape): | ||
if (architecture == 'dense'): | ||
return dense.discriminator(img_shape) | ||
if (architecture == 'conv1'): | ||
return conv1.discriminator(img_shape) | ||
if (architecture == 'conv2'): | ||
return conv2.discriminator(img_shape) | ||
if (architecture == 'resnet'): | ||
return resnet.discriminator(img_shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from keras.layers import Input, Dense, Reshape, Flatten, Dropout | ||
from keras.layers import BatchNormalization, Activation, ZeroPadding2D | ||
from keras.layers.advanced_activations import LeakyReLU | ||
from keras.layers.convolutional import UpSampling2D, Conv2D | ||
from keras.models import Sequential, Model | ||
|
||
import numpy as np | ||
|
||
def generator(latent_dim, img_shape): | ||
model = Sequential() | ||
|
||
model.add(Dense(128 * 8 * 8, activation="relu", input_dim=latent_dim)) | ||
model.add(Reshape((8, 8, 128))) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(UpSampling2D()) | ||
model.add(Conv2D(128, kernel_size=3, padding="same")) | ||
model.add(Activation("relu")) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(UpSampling2D()) | ||
model.add(Conv2D(64, kernel_size=3, padding="same")) | ||
model.add(Activation("relu")) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(Conv2D(img_shape[2], kernel_size=3, padding='same')) | ||
model.add(Activation("tanh")) | ||
|
||
model.summary() | ||
|
||
noise = Input(shape=(latent_dim,)) | ||
img = model(noise) | ||
|
||
return Model(noise, img) | ||
|
||
|
||
def discriminator(img_shape): | ||
|
||
model = Sequential() | ||
|
||
model.add(Conv2D(16, kernel_size=3, strides=2, input_shape=img_shape, padding="same")) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dropout(0.25)) | ||
model.add(Conv2D(32, kernel_size=3, strides=2, padding="same")) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dropout(0.25)) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(Conv2D(64, kernel_size=3, strides=2, padding="same")) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dropout(0.25)) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(Conv2D(128, kernel_size=3, strides=1, padding="same")) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dropout(0.25)) | ||
model.add(Flatten()) | ||
model.add(Dense(1, activation='sigmoid')) | ||
model.summary() | ||
|
||
img = Input(shape=img_shape) | ||
validity = model(img) | ||
|
||
return Model(img, validity) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from keras.layers import Input, Dense, Reshape, Flatten, Dropout | ||
from keras.layers import BatchNormalization, Activation, ZeroPadding2D | ||
from keras.layers.advanced_activations import LeakyReLU | ||
from keras.layers.convolutional import UpSampling2D, Conv2D | ||
from keras.models import Sequential, Model | ||
|
||
import numpy as np | ||
|
||
def generator(latent_dim, img_shape): | ||
model = Sequential() | ||
|
||
model.add(Dense(128 * 32 * 32, activation="relu", input_dim=latent_dim)) | ||
model.add(Reshape((32, 32, 128))) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
#model.add(UpSampling2D()) | ||
model.add(Conv2D(128, kernel_size=3, padding="same")) | ||
model.add(Activation("relu")) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
#model.add(UpSampling2D()) | ||
model.add(Conv2D(64, kernel_size=3, padding="same")) | ||
model.add(Activation("relu")) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(UpSampling2D()) | ||
model.add(Conv2D(32, kernel_size=3, padding="same")) | ||
model.add(Activation("relu")) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(UpSampling2D()) | ||
model.add(Conv2D(16, kernel_size=3, padding="same")) | ||
model.add(Activation("relu")) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(Conv2D(16, kernel_size=4, strides=2, padding="same")) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Conv2D(16, kernel_size=4, strides=2, padding="same")) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Conv2D(img_shape[2], kernel_size=3, padding='same')) | ||
model.add(Activation("tanh")) | ||
|
||
model.summary() | ||
|
||
noise = Input(shape=(latent_dim,)) | ||
img = model(noise) | ||
|
||
return Model(noise, img) | ||
|
||
|
||
def discriminator(img_shape): | ||
|
||
model = Sequential() | ||
|
||
model.add(Conv2D(16, kernel_size=3, strides=1, input_shape=img_shape, padding="same")) | ||
model.add(BatchNormalization()) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dropout(0.25)) | ||
model.add(Conv2D(32, kernel_size=3, strides=2, padding="same")) | ||
#model.add(ZeroPadding2D(padding=((0,1),(0,1)))) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dropout(0.25)) | ||
model.add(Conv2D(64, kernel_size=3, strides=2, padding="same")) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dropout(0.25)) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(Conv2D(128, kernel_size=3, strides=1, padding="same")) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dropout(0.25)) | ||
model.add(Flatten()) | ||
model.add(Dense(128, activation='relu')) | ||
model.add(Dense(64, activation='relu')) | ||
model.add(Dense(16, activation='relu')) | ||
model.add(Dense(1, activation='sigmoid')) | ||
model.summary() | ||
|
||
img = Input(shape=img_shape) | ||
validity = model(img) | ||
|
||
return Model(img, validity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from keras.layers import Input, Dense, Reshape, Flatten, Dropout | ||
from keras.layers import BatchNormalization, Activation, ZeroPadding2D | ||
from keras.layers.advanced_activations import LeakyReLU | ||
from keras.layers.convolutional import UpSampling2D, Conv2D | ||
from keras.models import Sequential, Model | ||
|
||
import numpy as np | ||
|
||
def generator(latent_dim, img_shape): | ||
|
||
model = Sequential() | ||
|
||
model.add(Dense(256, input_dim=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(1024)) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(BatchNormalization(momentum=0.8)) | ||
model.add(Dense(np.prod(img_shape), activation='tanh')) | ||
model.add(Reshape(img_shape)) | ||
|
||
model.summary() | ||
|
||
noise = Input(shape=(latent_dim,)) | ||
img = model(noise) | ||
|
||
return Model(noise, img) | ||
|
||
|
||
def discriminator(img_shape): | ||
|
||
model = Sequential() | ||
|
||
model.add(Flatten(input_shape=img_shape)) | ||
model.add(Dense(512)) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dense(256)) | ||
model.add(LeakyReLU(alpha=0.2)) | ||
model.add(Dense(1, activation='sigmoid')) | ||
model.summary() | ||
|
||
img = Input(shape=img_shape) | ||
validity = model(img) | ||
|
||
return Model(img, validity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from keras.layers import Input, Dense, Reshape, Flatten, Dropout, Add, Lambda | ||
from keras.layers import BatchNormalization, Activation, ZeroPadding2D, GlobalAveragePooling2D, AveragePooling2D | ||
from keras.layers.advanced_activations import LeakyReLU | ||
from keras.layers.convolutional import UpSampling2D, Conv2D | ||
from keras.models import Sequential, Model | ||
|
||
import numpy as np | ||
|
||
from libs.blocks import ResidualBlock, OptimizedResBlockDisc1 | ||
|
||
def generator(latent_dim, img_shape): | ||
|
||
noise = Input(shape=(latent_dim,)) | ||
|
||
x = Dense(128 * 4 * 4)(noise) | ||
x = Reshape((4, 4, 128))(x) | ||
x = ResidualBlock(128, 3, 'up')(x) | ||
x = ResidualBlock(128, 3, 'up')(x) | ||
x = ResidualBlock(128, 3, 'up')(x) | ||
x = BatchNormalization()(x) | ||
x = Activation("relu")(x) | ||
x = Conv2D(img_shape[2], kernel_size=3, padding="same")(x) | ||
img = Activation("tanh")(x) | ||
|
||
|
||
model = Model(noise, img) | ||
model.summary() | ||
|
||
return model | ||
|
||
|
||
def discriminator(img_shape): | ||
img = Input(shape=img_shape) | ||
|
||
x = Reshape(img_shape)(img) | ||
x = OptimizedResBlockDisc1(128)(x) | ||
x = ResidualBlock(128, 3, resample='down')(x) | ||
x = ResidualBlock(128, 3, resample=None)(x) | ||
x = ResidualBlock(128, 3, resample=None)(x) | ||
x = Activation("relu")(x) | ||
x = GlobalAveragePooling2D()(x) | ||
validity = Dense(1)(x) | ||
|
||
model = Model(img, validity) | ||
model.summary() | ||
|
||
return model | ||
|
Oops, something went wrong.