Beispiel #1
0
    def run(self, epochs):
        #CIFAR

        dataset = DataSet.Cifar()
        self.trX, self.trY, self.teX, self.teY = dataset.create_sets()
        epochs = 50000 * epochs

        self.Train()
        self.Test()

        with tf.train.MonitoredTrainingSession(
                checkpoint_dir=
                "Networkfile/tfconvtest",  # 세이브, 그래프, 초기화 모두 다 포함되있음.
                hooks=[tf.train.StopAtStepHook(last_step=epochs)],
                save_checkpoint_secs=300,
                save_summaries_steps=50) as sess:

            while not (sess.should_stop()):
                _, loss, step = sess.run(
                    [self.train_op, self.cost, self.global_step],
                    feed_dict={
                        self.p_keep_conv: 0.8,
                        self.p_keep_hidden: 0.5
                    })

                if (step % 1000 == 0):
                    accuracy = sess.run(self.acc_op,
                                        feed_dict={
                                            self.p_keep_conv: 1.0,
                                            self.p_keep_hidden: 1.0
                                        })
                    print(accuracy)
Beispiel #2
0
import tensorflow as tf
import numpy as np
import NNutils
import DataSet

from datetime import datetime

dataset = DataSet.Cifar()
trX, trY, teX, teY = dataset.create_sets()


def NN(X):
    w1 = tf.Variable(tf.random_normal([32 * 32 * 3, 2048], stddev=0.1))
    b1 = tf.Variable(tf.zeros([2048]))

    w2 = tf.Variable(tf.random_normal(
        [2048, 1400], stddev=0.1))  #MNIST 숫자가 10개이므로(0~9) 10이다.
    b2 = tf.Variable(tf.zeros([1400]))

    w3 = tf.Variable(tf.random_normal([1400, 900], stddev=0.1))
    b3 = tf.Variable(tf.zeros([900]))

    w4 = tf.Variable(tf.random_normal([900, 600], stddev=0.1))
    b4 = tf.Variable(tf.zeros([600]))

    w5 = tf.Variable(tf.random_normal([600, 300], stddev=0.1))
    b5 = tf.Variable(tf.zeros([300]))

    w6 = tf.Variable(tf.random_normal([300, 10], stddev=0.1))
    b6 = tf.Variable(tf.zeros([10]))