예제 #1
0
 def setUpClass(cls):
     cls.train_dataset, cls.train_labels, cls.valid_dataset, cls.valid_labels, cls.test_dataset, cls.test_labels = get_data_4d()
     dataholder = DataHolder(cls.train_dataset,
                             cls.train_labels,
                             cls.valid_dataset,
                             cls.valid_labels,
                             cls.test_dataset,
                             cls.test_labels)
     config = Config()
     cls.model = CNNModel(config, dataholder)
예제 #2
0
import numpy as np
import inspect
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

from util import run_test, get_data_4d, get_time
from CNN import CNNModel, train_model, check_valid
from DataHolder import DataHolder
from Config import Config

train_dataset, train_labels, valid_dataset, valid_labels, test_dataset, test_labels = get_data_4d()
my_dataholder = DataHolder(train_dataset,
                           train_labels,
                           valid_dataset,
                           valid_labels,
                           test_dataset,
                           test_labels)


number_of_exp = 10
DECAY = np.random.random_sample([number_of_exp])
DECAY = np.append(DECAY, 0.96)
number_of_exp += 1
DECAY.sort()
results = []
duration = []
예제 #3
0
def main():
    """
    Basic script that shows the training of the model,
    the accuracy of the test and valid datasets, and
    the prediction of one specific image.
    """
    train_dataset, train_labels, valid_dataset, valid_labels, test_dataset, test_labels = get_data_4d(
    )
    # my_config = Config()
    my_config = Config(learning_rate=0.52660658241,
                       dropout=0.75,
                       batch_size=230,
                       steps_for_decay=800,
                       num_filters_1=12,
                       hidden_nodes_3=300,
                       hidden_nodes_1=900,
                       decay_rate=0.349144998004,
                       num_filters_2=24,
                       patch_size=11,
                       image_size=28,
                       hidden_nodes_2=600)
    my_dataholder = DataHolder(train_dataset, train_labels, valid_dataset,
                               valid_labels, test_dataset, test_labels)
    my_model = CNNModel(my_config, my_dataholder)
    train_model(my_model, my_dataholder, 4 * 10001, 1000)
    print("check_valid = ", check_valid(my_model))
    print("check_test = ", check_test(my_model))
    one_example = test_dataset[0]
    one_example = one_example.reshape(1, one_example.shape[0],
                                      one_example.shape[1],
                                      one_example.shape[2])
    prediction = chr(one_prediction(my_model, one_example) + ord('A'))
    real = chr(np.argmax(test_labels[0]) + ord('A'))
    print("Prediction = {}".format(prediction))
    print("Real label = {}".format(real))