Ejemplo n.º 1
0
    def btnRun_Clicked(self):
        if self.image == '':
            msg_box_img = QMessageBox()
            msg_box.setWindowTitle("Warning")
            msg_box_img.setIcon(QMessageBox.Question)
            msg_box_img.setText(
                'The test image had not been loaded.\n Would you like to use the default image?'
            )
            msg_box_img.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
            img_retval = msg_box_img.exec_()
            if img_retval == QMessageBox.Yes:
                self.image = DEFAULT_IMAGE
                self.pimage = QPixmap(self.image)
                self.limage.setPixmap(self.pimage)
        if self.model == '':
            msg_box_model = QMessageBox()
            msg_box.setWindowTitle("Warning")
            msg_box_model.setText(
                'The model had not been loaded.\n Would you like to use the default model?'
            )
            msg_box_model.setIcon(QMessageBox.Question)
            msg_box_model.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
            model_retval = msg_box_model.exec_()
            if model_retval == QMessageBox.Yes:
                self.model = DEFAULT_MODEL
                modelpx = QPixmap("images/model.png")
                modelpx = modelpx.scaled(256, 256)
                self.lmodel.setPixmap(modelpx)

        msg_box = QMessageBox()
        msg_box.setWindowTitle("Finish")
        if self.image != '' and self.model != '':
            cnn = neuralNetwork(self.image, self.model)
            self.y_preds = cnn.predict()

            real_lm = revertPredict(self.y_preds)
            self.print_prediction(real_lm)
            self.glLabel.setPixmap(self.pimage)

            msg_box.setText("Finish process !")
        else:
            msg_box = QMessageBox()
            msg_box.setText("The image and the model do not empty !")
        msg_box.exec_()
Ejemplo n.º 2
0
NOS_EPISODES = 250
SAVE_PATH = "./models/"
if not os.path.exists(SAVE_PATH):
    os.mkdir(SAVE_PATH)
RENDER_GAME = False

# Setting up Gym
env = gym.make(ENV_NAME)
logger = benchmark()

# Finding the Network Shape
action_space = env.action_space.n
observation_space = env.observation_space.shape

# Initializing neural network
nn_solver = neuralNetwork(action_space, observation_space)

# Running Q Learning
for episode in range(NOS_EPISODES):
    state = env.reset()
    state = np.reshape(state, (1, observation_space[0]))
    time_step = 0
    terminate = False
    while True:
        # Render Game
        if RENDER_GAME:
            env.render()
        # Increment Time Step
        time_step = time_step + 1
        # Take Action
        action = nn_solver.act(state, env)
Ejemplo n.º 3
0
def show_image(data):
    values = data.split(',')
    image_array = np.asfarray(values[1:]).reshape(28, 28)
    plt.imshow(image_array, cmap='Greys', interpolation='None')
    plt.show()

# number of input nodes is a number of pixels
input_nodes = 784
hidden_nodes = 100
# each output node corresponds to particular number
output_nodes = 10
learning_rate = 0.3
# number of training epochs
epochs = 2

n = neuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)

# load train data
train_data_list = load_train_data(train_data_location)

# start training
print('Start training')
for i in range(epochs):
    for sample in train_data_list:
        #split sample
        values = sample.split(',')
        # scaling of inputs to the range (0.01, 1)
        inputs = np.asfarray(values[1:])/255.0 * 0.99 +0.01
        # choose 0.01 target value for outputs that doesn't correspond to label
        targets = np.zeros(output_nodes) + 0.01
        # and 0.99 otherwise
Ejemplo n.º 4
0
import neural_network as nk
import numpy
import matplotlib.pyplot as pl
import scipy.special
import scipy.ndimage.interpolation
import json
import time
import progressbar

# 测试神经网络
if __name__ == "__main__":
	input_nodes = nk.input_nodes
	hidden_nodes = nk.hidden_nodes
	hidden_nodes_2 = nk.hidden_nodes_2
	#hidden_nodes_3 = nk.hidden_nodes_3
	output_nodes = nk.output_nodes
	learningrate = nk.learningrate
	Network = nk.neuralNetwork(input_nodes,hidden_nodes,hidden_nodes_2,output_nodes,learningrate)
	nk.test(Network,"mnist_test.csv")
	

# hidden_nodes = 200 lr = 0.01 performance = 97.34
from neural_network import neuralNetwork

import numpy as np

num_input_nodes = 784
num_hidden_nodes = 200  # random value -> we can choose the best value by heuristic
num_output_nodes = 10  # label is between 0 ~ 9
learning_rate = 0.1  # random value -> we can choose the best value by heuristic

neural_network = neuralNetwork(num_input_nodes, num_hidden_nodes,
                               num_output_nodes, learning_rate)


def training():
    training_data_file = open("../mnist_dataset/mnist_train_100.csv", 'r')
    training_data_list = training_data_file.readlines()
    training_data_file.close()

    epochs = 5  # random value -> we can choose the best value by heuristic

    print("Start training!")
    for e in range(epochs):
        for record in training_data_list:
            all_values = record.split(',')
            inputs = (np.asfarray(all_values[1:]) / 255.0 * 0.99
                      ) + 0.01  # adjust input value to between 0.01 and 0.99

            targets = np.zeros(num_output_nodes) + 0.01  # To avoid 0

            targets[int(all_values[0])] = 0.99  # answer target