본문 바로가기

컴퓨터이야기

plot_model

The first step is to define the discriminator model.

 

The model must take a sample image from our dataset as input and output a classification prediction as to whether the sample is real or fake. This is a binary classification problem.

  • Inputs: Image with three color channel and 32×32 pixels in size.
  • Outputs: Binary classification, likelihood the sample is real (or fake).
  •  

plot_model 을 위해서는 아래 라이브러리를 순차적으로 설치해야 한다.

pip install pydot

pip install pydotplus

pip install graphviz

그래도 안되면 여기서 윈도우 실행 파일을 가져와서 설치하고 path를 지정해준다.

graphviz.org/download/

 

 

Download

 

graphviz.org

 

from keras.datasets.cifar100 import load_data
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.optimizers import Adam
from keras.layers import Dense, Conv2D, Flatten, Dropout, LeakyReLU
from keras.utils.vis_utils import plot_model



(x_train, y_train), (x_test, y_test) = load_data()

# print('Train', x_train.shape, y_train.shape)
# print('Test', x_test.shape, y_test.shape)
#
# for i in range(49):
# plt.subplot(7, 7, 1 + i)
# plt.axis('off')
# plt.imshow(x_train[i])
# plt.show()


# define the standalone discriminator model
def get_discriminator(in_shape=(32,32,3)):
model = Sequential()
model.add(Conv2D(64, (3,3), padding='same', input_shape=in_shape))
model.add(LeakyReLU(alpha=0.2))
model.add(Conv2D(128, (3,3), strides=(2,2), padding='same'))
model.add(LeakyReLU(alpha=0.2))
model.add(Conv2D(128, (3,3), strides=(2,2), padding='same'))
model.add(LeakyReLU(alpha=0.2))
model.add(Conv2D(256, (3,3), strides=(2,2), padding='same'))
model.add(LeakyReLU(alpha=0.2))

model.add(Flatten())
model.add(Dropout(0.4))
model.add(Dense(1, activation='sigmoid'))
# compile model
opt = Adam(lr=0.0002, beta_1=0.5)
model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])
return model

discriminator = get_discriminator()

discriminator.summary()
plot_model(discriminator, to_file='discriminator_plot.png', show_shapes=True, show_layer_names=True)

 

 

'컴퓨터이야기' 카테고리의 다른 글

편집거리 알고리즘 Levenshtein Distance(Edit Distance Algorithm)  (0) 2021.11.09
valence 원자가, 혹은 결합의 의미  (0) 2021.11.02
CIFAR-10  (0) 2021.02.02
Wasserstein Distance  (0) 2021.01.26
Lipschitz-continuous function  (0) 2021.01.26