close_btn
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

1.기본세팅

 

##Source:

https://github.com/ageron/handson-ml/blob/master/11_deep_learning.ipynb

 

from __future__ import division, print_function, unicode_literals

 

import numpy as np

import os

from pandas import DataFrame

 

def reset_graph(seed=42):

    tf.reset_default_graph()

    tf.set_random_seed(seed)

    np.random.seed(seed)

 

%matplotlib inline

import matplotlib

import matplotlib.pyplot as plt

plt.rcParams['axes.labelsize'] = 14

plt.rcParams['xtick.labelsize'] = 12

plt.rcParams['ytick.labelsize'] = 12

 

# Where to save the figures

PROJECT_ROOT_DIR = "C:/Users/Minjeong/Desktop/week2/tobigs/"

CHAPTER_ID = "tensorflow"

 

def save_fig(fig_id, tight_layout=True):

    path = os.path.join(PROJECT_ROOT_DIR, "images", CHAPTER_ID, fig_id + ".png")

    print("Saving figure", fig_id)

    if tight_layout:

        plt.tight_layout()

    plt.savefig(path, format='png', dpi=300)

# Cell # 2

from IPython.display import clear_output, Image, display, HTML

 

def strip_consts(graph_def, max_const_size=32):

    """Strip large constant values from graph_def."""

    strip_def = tf.GraphDef()

    for n0 in graph_def.node:

        n = strip_def.node.add()

        n.MergeFrom(n0)

        if n.op == 'Const':

            tensor = n.attr['value'].tensor

            size = len(tensor.tensor_content)

            if size > max_const_size:

                tensor.tensor_content = b"<stripped %d bytes>"%size

    return strip_def

 

def show_graph(graph_def, max_const_size=32):

    """Visualize TensorFlow graph."""

    if hasattr(graph_def, 'as_graph_def'):

        graph_def = graph_def.as_graph_def()

    strip_def = strip_consts(graph_def, max_const_size=max_const_size)

    code = """

        <script>

          function load() {{

            document.getElementById("{id}").pbtxt = {data};

          }}

        </script>

        <link rel="import" href="https://tensorboard.appspot.com/tf-graph-basic.build.html" onload=load()>

        <div style="height:600px">

          <tf-graph-basic id="{id}"></tf-graph-basic>

        </div>

    """.format(data=repr(str(strip_def)), id='graph'+str(np.random.rand()))

 

    iframe = """

        <iframe seamless style="width:1200px;height:620px;border:0" srcdoc="{}"></iframe>

    """.format(code.replace('"', '&quot;'))

    display(HTML(iframe))

# Cell # 12

from tensorflow.examples.tutorials.mnist import input_data

import tensorflow as tf

from sklearn.datasets import fetch_california_housing

from sklearn.preprocessing import StandardScaler

 

mnist = input_data.read_data_sets("/tmp/data/")# Cell # 1

 

X_train = mnist.train.images

X_test = mnist.test.images

y_train = mnist.train.labels.astype("int")

y_test = mnist.test.labels.astype("int")

 

 

2. epoch 50으로 늘려본다.

 

n_inputs = 28*28  # MNIST

n_hidden1 = 300

n_hidden2 = 100

n_outputs = 10   #0123456789

 

reset_graph()

 

X = tf.placeholder(tf.float32, shape=(None, n_inputs), name="X")

y = tf.placeholder(tf.int64, shape=(None), name="y")

 

with tf.name_scope("dnn"):

    hidden1 = tf.layers.dense(X, n_hidden1, name="hidden1",

                              activation=tf.nn.sigmoid)

    hidden2 = tf.layers.dense(hidden1, n_hidden2, name="hidden2",

                              activation=tf.nn.sigmoid)

    logits = tf.layers.dense(hidden2, n_outputs, name="outputs")

   

with tf.name_scope("loss"):

    xentropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y, logits=logits)

    loss = tf.reduce_mean(xentropy, name="loss")

   

learning_rate = 0.01

 

with tf.name_scope("train"):

    optimizer = tf.train.GradientDescentOptimizer(learning_rate)

    training_op = optimizer.minimize(loss)

   

with tf.name_scope("eval"):

    correct = tf.nn.in_top_k(logits, y, 1)

    accuracy = tf.reduce_mean(tf.cast(correct, tf.float32))

   

init = tf.global_variables_initializer()

 

n_epochs = 50

batch_size = 50

 

with tf.Session() as sess:

    init.run()

    for epoch in range(n_epochs):

        for iteration in range(mnist.train.num_examples // batch_size):

            X_batch, y_batch = mnist.train.next_batch(batch_size)

            sess.run(training_op, feed_dict={X: X_batch, y: y_batch})

        acc_train = accuracy.eval(feed_dict={X: X_batch, y: y_batch})

        acc_test = accuracy.eval(feed_dict={X: mnist.test.images, y: mnist.test.labels})

        print(epoch, "Train accuracy:", acc_train, "Test accuracy:", acc_test)

 

에폭만 늘린다고  일은 아니다. accuracy 92%정도로 증가했지만 원하는 accuracy 근처에도 못갔다.

 

3. hidden layer & regularization

 

#layer 5 정도로   깊게 만들어줌으로써 성능을 높여본다.

overfitting 문제를 해결하기 위해 regularization 해준다L2 사용했다.

 

n_inputs = 28*28  # MNIST

n_hidden1 = 300

n_hidden2 = 100

n_hidden3 = 100

n_hidden4 = 100

n_hidden5 = 100

n_outputs = 10   #0123456789

 

reset_graph()

 

X = tf.placeholder(tf.float32, shape=(None, n_inputs), name="X")

y = tf.placeholder(tf.int64, shape=(None), name="y")

 

with tf.name_scope("dnn"):

    hidden1 = tf.layers.dense(X, n_hidden1, name="hidden1", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.sigmoid)

    hidden2 = tf.layers.dense(hidden1, n_hidden2, name="hidden2", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.sigmoid)

    hidden3 = tf.layers.dense(hidden2, n_hidden3, name="hidden3", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.sigmoid)

    hidden4 = tf.layers.dense(hidden3, n_hidden4, name="hidden4", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.sigmoid)

    hidden5 = tf.layers.dense(hidden4, n_hidden5, name="hidden5", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.sigmoid)

    logits = tf.layers.dense(hidden2, n_outputs, name="outputs")

   

0 Train accuracy: 0.58 Test accuracy: 0.5749

1 Train accuracy: 0.72 Test accuracy: 0.6744

2 Train accuracy: 0.74 Test accuracy: 0.7513

3 Train accuracy: 0.82 Test accuracy: 0.7997

4 Train accuracy: 0.78 Test accuracy: 0.8238

5 Train accuracy: 0.86 Test accuracy: 0.8422

6 Train accuracy: 0.88 Test accuracy: 0.8564

7 Train accuracy: 0.88 Test accuracy: 0.8662

8 Train accuracy: 0.92 Test accuracy: 0.876

9 Train accuracy: 0.92 Test accuracy: 0.8814

10 Train accuracy: 0.86 Test accuracy: 0.8862

11 Train accuracy: 0.98 Test accuracy: 0.8919

12 Train accuracy: 0.92 Test accuracy: 0.8956

13 Train accuracy: 0.9 Test accuracy: 0.8967

14 Train accuracy: 0.9 Test accuracy: 0.9005

15 Train accuracy: 0.92 Test accuracy: 0.8998

16 Train accuracy: 0.86 Test accuracy: 0.9035

17 Train accuracy: 0.9 Test accuracy: 0.9048

18 Train accuracy: 0.92 Test accuracy: 0.9054

19 Train accuracy: 0.86 Test accuracy: 0.9076

 

4. activation function

 

#활성함수를 sigmoid대신 Relu 사용해봄으로써 vanishing gd 인한 문제를 개선해본다.

 

with tf.name_scope("dnn"):

    hidden1 = tf.layers.dense(X, n_hidden1, name="hidden1", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    hidden2 = tf.layers.dense(hidden1, n_hidden2, name="hidden2", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    hidden3 = tf.layers.dense(hidden2, n_hidden3, name="hidden3", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    hidden4 = tf.layers.dense(hidden3, n_hidden4, name="hidden4", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    hidden5 = tf.layers.dense(hidden4, n_hidden5, name="hidden5", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    logits = tf.layers.dense(hidden2, n_outputs, name="outputs")

   

0 Train accuracy: 0.96 Test accuracy: 0.9011

1 Train accuracy: 0.92 Test accuracy: 0.9214

2 Train accuracy: 0.92 Test accuracy: 0.9288

3 Train accuracy: 0.92 Test accuracy: 0.9359

4 Train accuracy: 0.96 Test accuracy: 0.9414

5 Train accuracy: 0.94 Test accuracy: 0.9444

6 Train accuracy: 0.94 Test accuracy: 0.9497

7 Train accuracy: 0.96 Test accuracy: 0.9521

8 Train accuracy: 0.92 Test accuracy: 0.9544

9 Train accuracy: 0.92 Test accuracy: 0.9578

10 Train accuracy: 0.98 Test accuracy: 0.9583

11 Train accuracy: 0.92 Test accuracy: 0.9611

12 Train accuracy: 0.96 Test accuracy: 0.9622

13 Train accuracy: 1.0 Test accuracy: 0.9641

14 Train accuracy: 1.0 Test accuracy: 0.9659

15 Train accuracy: 0.96 Test accuracy: 0.9659

16 Train accuracy: 0.98 Test accuracy: 0.9661

17 Train accuracy: 0.98 Test accuracy: 0.9676

18 Train accuracy: 0.98 Test accuracy: 0.9695

19 Train accuracy: 0.96 Test accuracy: 0.9704

 

#accuracy 아주 많이 증가했다!!

 

5. lr 0.15로 늘려본다.

 

계속해서 accuracy 증가하고 있어서 lr  늘려본다

 

learning_rate = 0.15

0 Train accuracy: 1.0 Test accuracy: 0.9587

1 Train accuracy: 1.0 Test accuracy: 0.9677

2 Train accuracy: 1.0 Test accuracy: 0.9716

3 Train accuracy: 1.0 Test accuracy: 0.9783

4 Train accuracy: 1.0 Test accuracy: 0.9787

5 Train accuracy: 1.0 Test accuracy: 0.9812

6 Train accuracy: 1.0 Test accuracy: 0.9803

7 Train accuracy: 1.0 Test accuracy: 0.9797

8 Train accuracy: 1.0 Test accuracy: 0.9826

9 Train accuracy: 1.0 Test accuracy: 0.9813

10 Train accuracy: 1.0 Test accuracy: 0.9836

11 Train accuracy: 1.0 Test accuracy: 0.9826

12 Train accuracy: 1.0 Test accuracy: 0.9834

13 Train accuracy: 1.0 Test accuracy: 0.9838

14 Train accuracy: 1.0 Test accuracy: 0.9832

15 Train accuracy: 1.0 Test accuracy: 0.9837

16 Train accuracy: 1.0 Test accuracy: 0.9834

17 Train accuracy: 1.0 Test accuracy: 0.9828

18 Train accuracy: 1.0 Test accuracy: 0.9839

19 Train accuracy: 1.0 Test accuracy: 0.9831


#원하는 accuracy 아주 가까워 지고있다!! 
#
그러나 accuracy 왔다갔다 하는  보아 lr 조금 줄여보기로 한다.

 

6. optimizer - momentum, lr=0.1

# accuracy 더욱 높여보고자 optimizer 종류별로 시도해보기로한다.

# momentum 이전 gradient들의 경향을 반영하여  빠르게 optimum으로 수렴하게 한다.

또한 안장점이나 local minimum에서 빠져나올  있게 한다.

 

with tf.name_scope("train"):

    optimizer = tf.train.MomentumOptimizer(learning_rate=learning_rate, momentum=0.9)

    training_op = optimizer.minimize(loss)


0 Train accuracy: 1.0 Test accuracy: 0.9466

1 Train accuracy: 0.94 Test accuracy: 0.9589

2 Train accuracy: 1.0 Test accuracy: 0.9689

3 Train accuracy: 0.98 Test accuracy: 0.967

4 Train accuracy: 0.98 Test accuracy: 0.9708

5 Train accuracy: 1.0 Test accuracy: 0.9733

6 Train accuracy: 1.0 Test accuracy: 0.9717

7 Train accuracy: 1.0 Test accuracy: 0.9707

8 Train accuracy: 1.0 Test accuracy: 0.966

9 Train accuracy: 0.98 Test accuracy: 0.9692

10 Train accuracy: 1.0 Test accuracy: 0.9722

11 Train accuracy: 1.0 Test accuracy: 0.9707

12 Train accuracy: 1.0 Test accuracy: 0.9735

13 Train accuracy: 1.0 Test accuracy: 0.9722

14 Train accuracy: 0.98 Test accuracy: 0.9748

15 Train accuracy: 1.0 Test accuracy: 0.9728

16 Train accuracy: 1.0 Test accuracy: 0.9723

17 Train accuracy: 1.0 Test accuracy: 0.9738

18 Train accuracy: 0.98 Test accuracy: 0.9715

19 Train accuracy: 1.0 Test accuracy: 0.971

 

 

7. Optimizer – NAG

# momentum gd 같이 더해주지만, NAG velocity 벡터를 이동한 후에 gd 더해 주는 방법이다.

 

with tf.name_scope("train"):

    optimizer = tf.train.MomentumOptimizer(learning_rate=learning_rate, momentum=0.9, use_nesterov=True)

    training_op = optimizer.minimize(loss)

 

0 Train accuracy: 0.98 Test accuracy: 0.9556

1 Train accuracy: 1.0 Test accuracy: 0.9667

2 Train accuracy: 1.0 Test accuracy: 0.967

3 Train accuracy: 1.0 Test accuracy: 0.9695

4 Train accuracy: 1.0 Test accuracy: 0.9649

5 Train accuracy: 1.0 Test accuracy: 0.9717

6 Train accuracy: 1.0 Test accuracy: 0.9695

7 Train accuracy: 1.0 Test accuracy: 0.9704

8 Train accuracy: 1.0 Test accuracy: 0.969

9 Train accuracy: 0.98 Test accuracy: 0.9731

10 Train accuracy: 1.0 Test accuracy: 0.9714

11 Train accuracy: 1.0 Test accuracy: 0.9731

12 Train accuracy: 1.0 Test accuracy: 0.9725

13 Train accuracy: 1.0 Test accuracy: 0.9749

14 Train accuracy: 1.0 Test accuracy: 0.9748

15 Train accuracy: 1.0 Test accuracy: 0.9726

16 Train accuracy: 1.0 Test accuracy: 0.9734

17 Train accuracy: 1.0 Test accuracy: 0.9757

18 Train accuracy: 1.0 Test accuracy: 0.9745

19 Train accuracy: 1.0 Test accuracy: 0.9719

 

#이동후에 gd 더해주면  정확한 벡터가  것이라 생각해서  높은 accuracy 기대했는데 비슷하다.
#그래서 lr 0.1 조정해주고, epoch 10 늘려 30으로 설정해보았다.

 

n_inputs = 28*28  # MNIST

n_hidden1 = 300

n_hidden2 = 100

n_hidden3 = 100

n_hidden4 = 100

n_hidden5 = 100

n_outputs = 10   #0123456789

 

reset_graph()

 

X = tf.placeholder(tf.float32, shape=(None, n_inputs), name="X")

y = tf.placeholder(tf.int64, shape=(None), name="y")

 

with tf.name_scope("dnn"):

    hidden1 = tf.layers.dense(X, n_hidden1, name="hidden1", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    hidden2 = tf.layers.dense(hidden1, n_hidden2, name="hidden2", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    hidden3 = tf.layers.dense(hidden2, n_hidden3, name="hidden3", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    hidden4 = tf.layers.dense(hidden3, n_hidden4, name="hidden4", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    hidden5 = tf.layers.dense(hidden4, n_hidden5, name="hidden5", kernel_regularizer=tf.contrib.layers.l2_regularizer(0.01), activation=tf.nn.relu)

    logits = tf.layers.dense(hidden2, n_outputs, name="outputs")

   

with tf.name_scope("loss"):

    xentropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y, logits=logits)

    loss = tf.reduce_mean(xentropy, name="loss")

   

learning_rate = 0.05

 

with tf.name_scope("train"):

    optimizer = tf.train.MomentumOptimizer(learning_rate=learning_rate, momentum=0.9, use_nesterov=True)

    training_op = optimizer.minimize(loss)

   

with tf.name_scope("eval"):

    correct = tf.nn.in_top_k(logits, y, 1)

    accuracy = tf.reduce_mean(tf.cast(correct, tf.float32))

   

init = tf.global_variables_initializer()

 

n_epochs = 30

batch_size = 50

 

with tf.Session() as sess:

    init.run()

    for epoch in range(n_epochs):

        for iteration in range(mnist.train.num_examples // batch_size):

            X_batch, y_batch = mnist.train.next_batch(batch_size)

            sess.run(training_op, feed_dict={X: X_batch, y: y_batch})

        acc_train = accuracy.eval(feed_dict={X: X_batch, y: y_batch})

        acc_test = accuracy.eval(feed_dict={X: mnist.test.images, y: mnist.test.labels})

        print(epoch, "Train accuracy:", acc_train, "Test accuracy:", acc_test)


0 Train accuracy: 1.0 Test accuracy: 0.9593

1 Train accuracy: 0.96 Test accuracy: 0.9679

2 Train accuracy: 1.0 Test accuracy: 0.969

3 Train accuracy: 1.0 Test accuracy: 0.9751

4 Train accuracy: 1.0 Test accuracy: 0.9759

5 Train accuracy: 1.0 Test accuracy: 0.9739

6 Train accuracy: 1.0 Test accuracy: 0.9781

7 Train accuracy: 1.0 Test accuracy: 0.9811

8 Train accuracy: 1.0 Test accuracy: 0.9787

9 Train accuracy: 1.0 Test accuracy: 0.9779

10 Train accuracy: 1.0 Test accuracy: 0.9797

11 Train accuracy: 1.0 Test accuracy: 0.9782

12 Train accuracy: 1.0 Test accuracy: 0.978

13 Train accuracy: 1.0 Test accuracy: 0.9786

14 Train accuracy: 1.0 Test accuracy: 0.9833

15 Train accuracy: 1.0 Test accuracy: 0.98

16 Train accuracy: 1.0 Test accuracy: 0.9814

17 Train accuracy: 1.0 Test accuracy: 0.9832

18 Train accuracy: 1.0 Test accuracy: 0.9795

19 Train accuracy: 1.0 Test accuracy: 0.9821

20 Train accuracy: 0.98 Test accuracy: 0.981

21 Train accuracy: 1.0 Test accuracy: 0.9825

22 Train accuracy: 1.0 Test accuracy: 0.9842

23 Train accuracy: 1.0 Test accuracy: 0.9842

24 Train accuracy: 1.0 Test accuracy: 0.9842

25 Train accuracy: 1.0 Test accuracy: 0.985

26 Train accuracy: 1.0 Test accuracy: 0.9857

27 Train accuracy: 1.0 Test accuracy: 0.9858

28 Train accuracy: 1.0 Test accuracy: 0.9856

29 Train accuracy: 1.0 Test accuracy: 0.9858

 

# 0.9858 accuracy 보여줬다!

 

 욕심이 나서 lr 0.02 바꾸어 보기도 하였으나,

 

learning_rate = 0.02

 

0 Train accuracy: 0.96 Test accuracy: 0.9616

1 Train accuracy: 0.94 Test accuracy: 0.9714

2 Train accuracy: 1.0 Test accuracy: 0.9759

3 Train accuracy: 1.0 Test accuracy: 0.9759

4 Train accuracy: 1.0 Test accuracy: 0.9783

5 Train accuracy: 1.0 Test accuracy: 0.9762

6 Train accuracy: 1.0 Test accuracy: 0.9814

7 Train accuracy: 1.0 Test accuracy: 0.982

8 Train accuracy: 1.0 Test accuracy: 0.9793

9 Train accuracy: 1.0 Test accuracy: 0.9815

10 Train accuracy: 1.0 Test accuracy: 0.9828

11 Train accuracy: 1.0 Test accuracy: 0.9829

12 Train accuracy: 1.0 Test accuracy: 0.9841

13 Train accuracy: 1.0 Test accuracy: 0.9843

14 Train accuracy: 1.0 Test accuracy: 0.9838

15 Train accuracy: 1.0 Test accuracy: 0.984

16 Train accuracy: 1.0 Test accuracy: 0.9841

17 Train accuracy: 1.0 Test accuracy: 0.984

18 Train accuracy: 1.0 Test accuracy: 0.9838

19 Train accuracy: 1.0 Test accuracy: 0.9841

20 Train accuracy: 1.0 Test accuracy: 0.984

21 Train accuracy: 1.0 Test accuracy: 0.9839

22 Train accuracy: 1.0 Test accuracy: 0.9836

23 Train accuracy: 1.0 Test accuracy: 0.9838

24 Train accuracy: 1.0 Test accuracy: 0.9839

25 Train accuracy: 1.0 Test accuracy: 0.9839

26 Train accuracy: 1.0 Test accuracy: 0.9836

27 Train accuracy: 1.0 Test accuracy: 0.9838

28 Train accuracy: 1.0 Test accuracy: 0.9834

29 Train accuracy: 1.0 Test accuracy: 0.9839

 

 낮아진 accuracy..

 

w 늘려보고, lr=0.05 바꾸어 보았다!

 

n_inputs = 28*28  # MNIST

n_hidden1 = 300

n_hidden2 = 300

n_hidden3 = 300

n_hidden4 = 300

n_outputs = 10   #0123456789

 

learning_rate = 0.05

 

0 Train accuracy: 0.96 Test accuracy: 0.9573

1 Train accuracy: 0.98 Test accuracy: 0.9753

2 Train accuracy: 1.0 Test accuracy: 0.9761

3 Train accuracy: 1.0 Test accuracy: 0.9772

4 Train accuracy: 1.0 Test accuracy: 0.9783

5 Train accuracy: 1.0 Test accuracy: 0.9792

6 Train accuracy: 1.0 Test accuracy: 0.9796

7 Train accuracy: 1.0 Test accuracy: 0.979

8 Train accuracy: 1.0 Test accuracy: 0.9792

9 Train accuracy: 1.0 Test accuracy: 0.9805

10 Train accuracy: 1.0 Test accuracy: 0.9811

11 Train accuracy: 1.0 Test accuracy: 0.9839

12 Train accuracy: 1.0 Test accuracy: 0.9786

13 Train accuracy: 1.0 Test accuracy: 0.9833

14 Train accuracy: 1.0 Test accuracy: 0.9807

15 Train accuracy: 1.0 Test accuracy: 0.9816

16 Train accuracy: 1.0 Test accuracy: 0.9826

17 Train accuracy: 1.0 Test accuracy: 0.9836

18 Train accuracy: 1.0 Test accuracy: 0.98

19 Train accuracy: 1.0 Test accuracy: 0.9848

20 Train accuracy: 1.0 Test accuracy: 0.9827

21 Train accuracy: 1.0 Test accuracy: 0.9857

22 Train accuracy: 1.0 Test accuracy: 0.9848

23 Train accuracy: 1.0 Test accuracy: 0.9846

24 Train accuracy: 1.0 Test accuracy: 0.9863

25 Train accuracy: 1.0 Test accuracy: 0.9864

26 Train accuracy: 1.0 Test accuracy: 0.9865

27 Train accuracy: 1.0 Test accuracy: 0.9864

28 Train accuracy: 1.0 Test accuracy: 0.9865

29 Train accuracy: 1.0 Test accuracy: 0.9865

 

0.9865 accuracy 보여줬다!!

 

8. Optimizer – AdaGrad

 

with tf.name_scope("train"):

    optimizer = tf.train.AdagradOptimizer(learning_rate=learning_rate)

    training_op = optimizer.minimize(loss)

0 Train accuracy: 1.0 Test accuracy: 0.9597

1 Train accuracy: 1.0 Test accuracy: 0.9681

2 Train accuracy: 1.0 Test accuracy: 0.9768

3 Train accuracy: 1.0 Test accuracy: 0.9806

4 Train accuracy: 1.0 Test accuracy: 0.9805

5 Train accuracy: 1.0 Test accuracy: 0.9816

6 Train accuracy: 1.0 Test accuracy: 0.9832

7 Train accuracy: 1.0 Test accuracy: 0.9822

8 Train accuracy: 1.0 Test accuracy: 0.9839

9 Train accuracy: 1.0 Test accuracy: 0.9843

10 Train accuracy: 1.0 Test accuracy: 0.9847

11 Train accuracy: 1.0 Test accuracy: 0.9848

12 Train accuracy: 1.0 Test accuracy: 0.9848

13 Train accuracy: 1.0 Test accuracy: 0.9848

14 Train accuracy: 1.0 Test accuracy: 0.9852

15 Train accuracy: 1.0 Test accuracy: 0.9848

16 Train accuracy: 1.0 Test accuracy: 0.9854

17 Train accuracy: 1.0 Test accuracy: 0.9851

18 Train accuracy: 1.0 Test accuracy: 0.9853

19 Train accuracy: 1.0 Test accuracy: 0.9853

 

9. Optimizer - Adam

 

learning_rate = 0.03

 

with tf.name_scope("train"):

    optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)

    training_op = optimizer.minimize(loss)


0 Train accuracy: 0.88 Test accuracy: 0.9222

1 Train accuracy: 0.98 Test accuracy: 0.9356

2 Train accuracy: 0.96 Test accuracy: 0.9257

3 Train accuracy: 0.94 Test accuracy: 0.9449

4 Train accuracy: 0.92 Test accuracy: 0.9417

5 Train accuracy: 0.88 Test accuracy: 0.9354

6 Train accuracy: 0.94 Test accuracy: 0.9372

7 Train accuracy: 0.9 Test accuracy: 0.945

8 Train accuracy: 0.9 Test accuracy: 0.9448

9 Train accuracy: 0.92 Test accuracy: 0.9165

10 Train accuracy: 0.98 Test accuracy: 0.941

11 Train accuracy: 0.94 Test accuracy: 0.9438

12 Train accuracy: 0.98 Test accuracy: 0.9467

13 Train accuracy: 0.92 Test accuracy: 0.9236

14 Train accuracy: 0.98 Test accuracy: 0.9414

15 Train accuracy: 0.98 Test accuracy: 0.9414

16 Train accuracy: 0.98 Test accuracy: 0.939

17 Train accuracy: 0.94 Test accuracy: 0.933

18 Train accuracy: 0.9 Test accuracy: 0.9354

19 Train accuracy: 0.98 Test accuracy: 0.9401

 

#기대했던 adam 생각보다 좋은 성능을 보여주지 못했다.

 

결론

hidden layer 5

w 300

L2 regularization
활성함수는 Relu

learning rate 0.05
epoch
 30
Optimizer
 NAG 주었을 ,
0.9865
 가장 높은 정확도를 보였다 !

 


List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 R 소스 공유 게시판 이용 관련 공지사항 1 DataMarket 2014.05.21 26117
102 투빅스 8&9기 설 분석 과제 16' 뉴욕 택시 운행시간 예측 - 9기 최영제 :) 2018.02.24 3148
101 투빅스 8&9기 4주차 과제 Random Forest -9기 이잉걸 잉걸 2018.02.15 2758
100 투빅스 8&9기 4주차 과제 Naive Bayes Classification -9기 서석현 file 스르륵 2018.02.14 2691
99 투빅스 8&9기 3주차 과제 K-Nearest Neighbor, K-means 구현 -9기 신용재 1 신용재 2018.02.08 3209
98 투빅스 8&9기 3주차 과제 연관성 분석 - 9기 최영제 :) 2018.02.08 2878
97 투빅스 8&9기 2주차 과제 Gradient Descent, Softmax, Cross Entropy - 9기 서석현 file 스르륵 2018.02.02 2734
96 투빅스 8&9기 2주차 과제 회귀분석/로지스틱 - 9기 최영제 file :) 2018.02.02 3233
95 투빅스 8&9기 2주차 과제 Gradient Descent, Softmax, Cross Entropy - 9기 김명진 file kimji 2018.02.02 2628
94 투빅스 8&9기 1주차 과제 R 9기-신용재 file 신용재 2018.01.25 3052
93 투빅스 8&9기 1주차 과제 R 알고리즘 - 9기 서석현 file 스르륵 2018.01.25 3101
» 투빅스 7&8기 9주차 과제 Neural Network를 이용한 MNIST 분류 - 8기 김민정 민정e 2017.09.23 4433
91 투빅스 7&8기 9주차 과제 Neural Network를 이용한 MNIST 분류 - 8기 최서현 최서현 2017.09.22 4253
90 투빅스 7&8기 7주차 과제 유기동물 과제 - 8기 조양규 dial123 2017.09.14 4444
89 투빅스 7&8기 7주차 과제 유기동물입양예측 - 8기 김강열 김강열 2017.09.14 4190
88 투빅스 7&8기 6주차 과제 word2vec - 8기 황다솔 다솔 2017.08.31 4824
87 투빅스 7&8기 6주차 과제 TF-IDF 문서유사도 측정 - 8기 최서현 최서현 2017.08.31 4604
86 투빅스 7&8기 5주차 과제 Selenium Crawling - 8기 김강열 김강열 2017.08.24 4606
85 투빅스 7&8기 5주차 과제 Image Augmentation - 8기 김민정 김소희 최수정 황다솔 file 민정e 2017.08.24 4461
84 투빅스 7&8기 5주차 과제 Beautiful Soup 이용한 Crawling - 8기 류호성 file 류호성 2017.08.24 4409
83 투빅스 7&8기 4주차 과제 tree, RF, bagging, boosting 이용 분석 - 8기 조양규 file dial123 2017.08.17 4321
Board Pagination ‹ Prev 1 2 3 4 5 6 ... 7 Next ›
/ 7

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5