Пример #1
0
__author__ = 'JoJo'

# Import statements required to build, train, and test the networks
from pybrain.tools.shortcuts import buildNetwork
from pybrain.tools.datasets import mnist
from pybrain.structure.modules import LSTMLayer
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.tools.validation import ModuleValidator

# Import statement to keep track of time elapsed
import time
# Import statement to plot data
import matplotlib.pyplot as plt

path = "/Users/JoJo/Desktop/Macalester-Sophomore/COMP221/Final/MNIST"
(train, test) = mnist.makeMnistDataSets(path)

# Build the networks with increasing complexity in number of nodes in order to test if number of nodes affects error rate
# Trainers are created for each network and each network is trained once
# Then, I test the network against the actual dataset and get the mean squared error and see the connection between nodes and MSE
inputNode = 28*28
baselineNumberOfNodes = 10

numOutputNodes = 10
LSTMNetworkNumber = 1

LSTMNetworks = []
multipliers = [1,2,5,10]
overallError = []
testComparison = []
timeSpentBuilding = []
		start = clock()
		mse = ModuleValidator.MSE(n,ts)
		end = clock()
		duration = end - start
		writeFile(base + str(i) + "/evaluationTime.txt","The network tested in " + str(duration) + " seconds with an MSE of " + str(mse))#record the MSE
		
if __name__ == "__main__":
	#define constants
	rootPath = "/Users/hherman1/ConvolutionalNeuralNetwork/"
	resDir = rootPath + "results/"
	convDir = resDir + "convolutional/"
	lstmDir = resDir + "lstm/"
	ffDir = resDir + "feedforward/"
	MNISTDIR = "MNIST/"
	#build training and testing data sets
	(train,test) = makeMnistDataSets(rootPath + MNISTDIR)
	
	#designate testing values
	convolutionalTestValues = []
	lstmTestValues = [1,2,5,10]
	ffTestValues = [1,2,3,4,5,6]

	#build folder structure
	buildStructure(rootPath)
	
	#evaluate convolutional networks
	#RECCOMENDATION: Use the tensorflow implementation, also provided, or run no tests on the convolutional network, since these are exceptionally slow in pybrain.
	nets = buildConvolutionalNetworks(convDir,convolutionalTestValues)
	nets = trainNetworks(convDir,nets,train)
	testAccuracy(convDir,nets,test)
# Import statements required to build, train, and test the networks
from pybrain.tools.shortcuts import buildNetwork
from pybrain.tools.datasets import mnist
from pybrain.structure.modules import LSTMLayer
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.tools.validation import ModuleValidator

# Import statement to keep track of time elapsed
import time
# Import statement to plot data
import matplotlib.pyplot as plt

path = "MNIST/"
(train, test) = mnist.makeMnistDataSets(path)

# Build the networks with increasing complexity in number of nodes in order to test if number of nodes affects error rate
# Trainers are created for each network and each network is trained once
# Then, I test the network against the actual dataset and get the mean squared error and see the connection between nodes and MSE
inputNode = 28 * 28
baselineNumberOfNodes = 10

numOutputNodes = 10
LSTMNetworkNumber = 1

LSTMNetworks = []
multipliers = [1, 2, 5, 10]
overallError = []
testComparison = []
timeSpentBuilding = []
timeSpentTraining = []
timeSpentTesting = []
Пример #4
0
from pybrain.tools.shortcuts import buildNetwork
from pybrain.tools.validation import ModuleValidator
import matplotlib.pyplot as plt
import time

FirstStartTime = time.time()
print("Making Networks 1-6")
net1 = buildNetwork(28 * 28, 28, 10)
net2 = buildNetwork(28 * 28, 28 * 2, 10)
net3 = buildNetwork(28 * 28, 28 * 3, 10)
net4 = buildNetwork(28 * 28, 28 * 4, 10)
net5 = buildNetwork(28 * 28, 28 * 5, 10)
net6 = buildNetwork(28 * 28, 28 * 6, 10)

#Gets the training and test sets for MNIST stuff
(train, test) = mnist.makeMnistDataSets(
    "/Users/talhaAhsan/PycharmProjects/PythonCrashCourse/MNIST_data")
print("Training and Testing sets have been formed")
trainerrorlist = []
print("Starting backprop training")
timeTaken = []

starttime = time.time()
print("Training Network 1")
trainer1 = backprop.BackpropTrainer(net1, dataset=train)
score1 = trainer1.train()
trainerrorlist.append(score1)
timeTaken.append(time.time() - starttime)

starttime = time.time()
print("Training Network 2")
trainer2 = backprop.BackpropTrainer(net2, dataset=train)
Пример #5
0
from pybrain.tools.shortcuts import buildNetwork
from pybrain.tools.validation import ModuleValidator
import matplotlib.pyplot as plt
import time

FirstStartTime = time.time()
print("Making Networks 1-6")
net1 = buildNetwork(28*28, 28, 10)
net2 = buildNetwork(28*28, 28*2, 10)
net3 = buildNetwork(28*28, 28*3, 10)
net4 = buildNetwork(28*28, 28*4, 10)
net5 = buildNetwork(28*28, 28*5, 10)
net6 = buildNetwork(28*28, 28*6, 10)

#Gets the training and test sets for MNIST stuff
(train, test) = mnist.makeMnistDataSets("C:\\Users\\Talha Ahsan\\PycharmProjects\\PythonCrashCourse\\MNIST_data")
print("Training and Testing sets have been formed")
trainerrorlist = []
print("Starting backprop training")
timeTaken = []

starttime = time.time()
print("Training Network 1")
trainer1 = backprop.BackpropTrainer(net1, dataset= train)
score1 = trainer1.train()
trainerrorlist.append(score1)
timeTaken.append(time.time() - starttime)

starttime = time.time()
print("Training Network 2")
trainer2 = backprop.BackpropTrainer(net2, dataset= train)