Ejemplo n.º 1
0
def main():
    # Number of nodes
    # Number of input pixels
    input_nodes = 784
    # Arbitrary 
    hidden_nodes = 100
    # Number of options for output
    output_nodes = 10 

    learning_rate = 0.3

    network = nn.neuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)

    print("Training network! May take some time...")
    train(network, output_nodes)

    print("Test the network!")
    print("Options: ")
    print("    Enter a number, 0-9, to test the image from mnist_dataset/images/test")
    print("    Enter 'all' to test against all images in mnist_dataset/images/test")
    print("    Type 'q' to quit")

    choice = input("Input: ")

    while choice is not 'q':
        try:
            input_num = int(choice)
            test(network, input_num)
        except ValueError:
            if choice == 'all':
                test_all(network)
            else:
                print("Error - unknown command")

        choice = input("Input: ")
Ejemplo n.º 2
0
    def __init__(self):

        # Change this to whatever your emulator window name is
        self.WINDOW_NAME = WINDOW_NAME = "Super Mario 64 (U)"

        # Find window dimensions and apply padding
        self.DIMENSIONS = self.get_window_dimensions()
        PADDING_LEFT = 0
        PADDING_TOP = 70
        PADDING_RIGHT = 20
        PADDING_BOTTOM = 70
        self.DIMENSIONS = (self.DIMENSIONS[0] + PADDING_LEFT,
                           self.DIMENSIONS[1] + PADDING_TOP,
                           self.DIMENSIONS[2] - PADDING_LEFT - PADDING_RIGHT,
                           self.DIMENSIONS[3] - PADDING_TOP - PADDING_BOTTOM)

        assert self.DIMENSIONS != None, "Error: Could not find game window " + WINDOW_NAME
        #LEFT   = self.DIMENSIONS[0]
        #TOP    = self.DIMENSIONS[1]
        WIDTH = self.DIMENSIONS[2]
        HEIGHT = self.DIMENSIONS[3]

        # Neural network optimization.
        # Use 1 for no compression. Higher numbers will reduce the size of the neural network and input nodes.
        self.COMPRESSION = 8

        # Determine, based on compression, the width and height of the compressed input image.
        self.COMPRESSED_WIDTH = round(WIDTH / self.COMPRESSION)
        self.COMPRESSED_HEIGHT = round(HEIGHT / self.COMPRESSION)

        # Determine the size of each layer.
        self.INPUT_NODES = self.COMPRESSED_WIDTH * self.COMPRESSED_HEIGHT
        self.OUTPUT_NODES = 8
        self.HIDDEN_NODES_1 = round(
            (self.INPUT_NODES * 2 + self.OUTPUT_NODES) / 3)
        self.HIDDEN_NODES_2 = round(
            (self.INPUT_NODES + self.OUTPUT_NODES * 2) / 3)

        # Neural network settings
        self.LEARNING_RATE = 0.001  # How quickly nodes will be adjusted to compensate for error.
        self.KEYPRESS_THRESHOLD = 0.5  # The neural network must output a value higher than this in order for it to be considered a press.

        # Instantiate a neural network object
        self.neural_network = neuralnetwork.neuralNetwork(
            inputnodes=self.INPUT_NODES,
            hiddennodes1=self.HIDDEN_NODES_1,
            hiddennodes2=self.HIDDEN_NODES_2,
            outputnodes=self.OUTPUT_NODES,
            learningrate=self.LEARNING_RATE)
Ejemplo n.º 3
0
def initNetwork() -> neuralNetwork:
    with open("config.yml", 'r') as ymlfile:
        cfg = yaml.load(ymlfile, Loader=yaml.FullLoader)

    # Default configuration for 28x28 pixel images.
    input_nodes = cfg.get("input_nodes", 784)
    hidden_nodes = cfg.get("hidden_nodes", 200)
    output_nodes = cfg.get("output_nodes", 10)
    learning_rate = cfg.get("learning_rate", 0.01)

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

    if cfg.get("kernel", None):
        n.load(cfg.get("kernel"))
        print(f"loaded kernel {n.kernel_name}")

    return n
Ejemplo n.º 4
0
import numpy
import imageio
from tqdm import tqdm
from neuralnetwork import neuralNetwork

# ===学習モデルを読み込み開始====
parameters = numpy.load('trainedModel/parameters.npy')
# 入力層、隠れ層、出力層のノード数
input_nodes = int(parameters[0])
hidden_nodes = int(parameters[1])
output_nodes = int(parameters[2])
# 学習率
learning_rate = parameters[3]
# ニューラルネットワークのインスタンス生成
n = neuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)
# 保存した重みを読み込む
n.load_weights()
# ===学習モデルを読み込み終わり====

# run the network backwards, given a label, see what image it produces

# label to test
label = 6
# create the output signals for this label
targets = numpy.zeros(output_nodes) + 0.01
# all_values[0] is the target label for this record
targets[label] = 0.99
print(targets)

# get image data
image_data = n.backquery(targets)
Ejemplo n.º 5
0
import loadData as ld
import shutil
import os
import build_dataset as bd
import neuralnetwork as nn
import prediction as pr

# Check if data folder exists inside local git and delete it to have a clean folder available
if os.path.isdir('data'):
    shutil.rmtree('data')

ld.resize_dataset()

bd.buildDataSet('data/*.jpg')

nn.neuralNetwork()

pr.prediction()
Ejemplo n.º 6
0
    def neuralNetwork(self):

        return neuralNetwork()