From b418990448f461da50a732b4e66dd8e9066199d8 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Wed, 6 Mar 2019 23:16:36 +0000 Subject: Return inception score as well --- lenet.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lenet.py') diff --git a/lenet.py b/lenet.py index 3ddab06..5ed6705 100644 --- a/lenet.py +++ b/lenet.py @@ -13,6 +13,8 @@ import random from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split +from classifier_metrics_impl import classifier_score_from_logits + def import_mnist(): from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", reshape=False) @@ -126,10 +128,12 @@ def train_classifier(x_train, y_train, x_val, y_val, batch_size=128, epochs=100, def test_classifier(model, x_test, y_true): x_test = np.pad(x_test, ((0,0),(2,2),(2,2),(0,0)), 'constant') y_pred = model.predict(x_test) + logits = tf.convert_to_tensor(y_pred, dtype=tf.float32) + inception_score = tf.keras.backend.eval(classifier_score_from_logits(logits)) y_pred = np.argmax(y_pred, axis=1) y_true = np.argmax(y_true, axis=1) plot_example_errors(y_pred, y_true, x_test) - return accuracy_score(y_true, y_pred) + return accuracy_score(y_true, y_pred), inception_score def mix_data(X_train, y_train, X_validation, y_validation, train_gen, tr_labels_gen, val_gen, val_labels_gen, split=0): @@ -162,4 +166,4 @@ if __name__ == '__main__': x_train, y_train, x_val, y_val, x_t, y_t = import_mnist() print(y_t.shape) model = train_classifier(x_train[:100], y_train[:100], x_val, y_val, epochs=3) - test_classifier(model, x_t, y_t) + print(test_classifier(model, x_t, y_t)) -- cgit v1.2.3-54-g00ecf From 5d779afb5a9511323e3402537af172d68930d85c Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Wed, 6 Mar 2019 23:49:46 +0000 Subject: Replace softmax with relu as we apply it in the function anyway --- lenet.py | 3 ++- report/paper.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lenet.py') diff --git a/lenet.py b/lenet.py index 5ed6705..97479ed 100644 --- a/lenet.py +++ b/lenet.py @@ -64,7 +64,8 @@ def get_lenet(shape): model.add(Dense(units=120, activation='relu')) model.add(Dense(units=84, activation='relu')) - model.add(Dense(units=10, activation = 'softmax')) + #model.add(Dense(units=10, activation = 'softmax')) + model.add(Dense(units=10, activation = 'relu')) return model def plot_history(history, metric = None): diff --git a/report/paper.md b/report/paper.md index b4a2a63..0227b1e 100644 --- a/report/paper.md +++ b/report/paper.md @@ -10,7 +10,7 @@ $$ V (D,G) = E_{x~p_{data}(x)}[logD(x)] + E_{zp_z(z)}[log(1-D(G(z)))] $$ The issue with shallow architectures (**present the example we used for mode collapse**) can be ontain really fast training, while producing overall good results. -One of the main issues that raises from this kind of architectures is mode collapse. As the discriminator keeps getting +One of the main issues enctoured with GAN architectures is mode collapse. As the discriminator keeps getting better, the generator tries to focus on one single class label to improve its loss. This issue can be observed in figure \ref{fig:mode_collapse}, in which we can observe how after 200 thousand iterations, the output of the generator only represents few of the labels originally fed to train the network. At that point the loss function of the generator starts getting worse as shown in figure -- cgit v1.2.3-54-g00ecf