Пример #1
0
class MNISTConvNetTrainingTest(unittest.TestCase):
	def setUp(self):
		configPath = "MNIST2and3Config.ini"
		self.net = ConvNet(configPath)

		# import just images of 2s and 3s for now
		self.imagesOf2s = extract_mnist.getMNISTTrainingSamplesNum(2)
		self.imagesOf3s = extract_mnist.getMNISTTrainingSamplesNum(3)

	def testTrain2sAnd3s(self):
		numImages = 10 # number of images of each category

		# combine two data sets
		twos = self.imagesOf2s[0:numImages]
		threes = self.imagesOf3s[0:numImages]
		data = np.concatenate((twos, threes))

		# set up labels
		labels = []
		for i in xrange(numImages):
			labels.append("two")
		for i in xrange(numImages):
			labels.append("three")

		# epochs
		maxEpochs = 50
		epochsPerSave = 50

		# run test
		print "Start"
		self.net.trainSet(data, labels, maxEpochs, epochsPerSave)
		self.net.testSet(data, labels)
		self.net.saveFilters(maxEpochs)
Пример #2
0
class MNISTConvNetTestingTest(unittest.TestCase):
	def setUp(self):
		configPath = "MNIST2and3and7Config_twoConv-trained-100.ini"
		self.net = ConvNet(configPath)

		# import just images of 2s and 3s for now
		self.imagesOf2s = extract_mnist.getMNISTTestSamplesNum(2)
		self.imagesOf3s = extract_mnist.getMNISTTestSamplesNum(3)
		self.imagesOf7s = extract_mnist.getMNISTTestSamplesNum(7)

	def testTest2sAnd3sAnd7s(self):
		numImages = 1 # number of images of each category

		# combine two data sets
		#twos = self.imagesOf2s[0:numImages]
		threes = self.imagesOf3s[0:numImages]
		#sevens = self.imagesOf7s[0:numImages]
		#data = np.concatenate((twos, threes, sevens))

		# set up labels
		labels = []
		#for i in xrange(numImages):
		#	labels.append("two")
		for i in xrange(numImages):
		    labels.append("three")
		#for i in xrange(numImages):
	#		labels.append("seven")

		# run test
		self.net.testSet(threes, labels)
		self.net.saveFilters(100)
		self.net.saveActivations(100)
Пример #3
0
class ToyConvNetTrainingTest(unittest.TestCase):
	def setUp(self):
		configPath = "MultipleConvPoolLayersConfig.ini"
		imagePathPrefix = "../test_imgs/lines/"
		imagePaths = ["horiz_line0.png", "horiz_line1.png", "horiz_line2.png",
			"vert_line0.png", "vert_line1.png", "vert_line2.png"]
		self.labels = np.array(["horiz", "horiz", "horiz", "vert", "vert", "vert"])
		self.imageDim = 32
		self.numImages = 6
		assert len(self.labels) == self.numImages, "Not enough labels to run!"
		assert len(imagePaths) == self.numImages, "Not enough images to run!"

		self.net = ConvNet(configPath)
		self.images = np.zeros((self.numImages, self.imageDim, self.imageDim))
		for i in xrange(self.numImages):
			self.images[i] = misc.loadImage(imagePathPrefix + imagePaths[i])

	# def testTrain1Image(self):
	# 	data = np.zeros((1, self.imageDim, self.imageDim))
	# 	data[0] = np.array([self.images[0]])
	# 	maxEpochs = 100
	# 	epochsPerSave = 101 # no saving in this test

	# 	self.net.trainSet(data, np.array([self.labels[0]]), maxEpochs, epochsPerSave)
	# 	self.net.testSet(data, np.array([self.labels[0]]))

	# def testTrain6Images(self):
	# 	data = self.images
	# 	maxEpochs = 1000
	# 	epochsPerSave = 10001 # no saving in this test either

	# 	self.net.trainSet(data, self.labels, maxEpochs, epochsPerSave)

	def testTrain6ImagesAndTest(self):
		data = self.images
		maxEpochs = 500
		epochsPerSave = 500 # save at the end of this test

		self.net.trainSet(data, self.labels, maxEpochs, epochsPerSave)
		self.net.testSet(data, self.labels)
		self.net.saveFilters(maxEpochs) # for visualization
Пример #4
0
class MNISTConvNetTestingTest(unittest.TestCase):
	def setUp(self):
		configPath = "MNIST_10_Config.ini"
		self.net = ConvNet(configPath)

		# import all images
		self.imagesOf0s = extract_mnist.getMNISTTestSamplesNum(0)
		self.imagesOf1s = extract_mnist.getMNISTTestSamplesNum(1)
		self.imagesOf2s = extract_mnist.getMNISTTestSamplesNum(2)
		self.imagesOf3s = extract_mnist.getMNISTTestSamplesNum(3)
		self.imagesOf4s = extract_mnist.getMNISTTestSamplesNum(4)
		self.imagesOf5s = extract_mnist.getMNISTTestSamplesNum(5)
		self.imagesOf6s = extract_mnist.getMNISTTestSamplesNum(6)
		self.imagesOf7s = extract_mnist.getMNISTTestSamplesNum(7)
		self.imagesOf8s = extract_mnist.getMNISTTestSamplesNum(8)
		self.imagesOf9s = extract_mnist.getMNISTTestSamplesNum(9)

	def testTestAll(self):
		numImages = 100 # number of images of each category

		# combine all data sets
		zeros = self.imagesOf0s[0:numImages]
		ones = self.imagesOf1s[0:numImages]
		twos = self.imagesOf2s[0:numImages]
		threes = self.imagesOf3s[0:numImages]
		fours = self.imagesOf4s[0:numImages]
		fives = self.imagesOf5s[0:numImages]
		sixs = self.imagesOf6s[0:numImages]
		sevens = self.imagesOf7s[0:numImages]
		eights = self.imagesOf8s[0:numImages]
		nines = self.imagesOf9s[0:numImages]
		data = np.concatenate((zeros, ones, twos, threes, fours, fives, sixs, \
			sevens, eights, nines))

		# set up labels
		labels = []
		for i in xrange(numImages):
		 	labels.append("zero")
		for i in xrange(numImages):
		    labels.append("one")
		for i in xrange(numImages):
		 	labels.append("two")
		for i in xrange(numImages):
		    labels.append("three")
		for i in xrange(numImages):
		 	labels.append("four")
		for i in xrange(numImages):
		 	labels.append("five")
		for i in xrange(numImages):
		    labels.append("six")
		for i in xrange(numImages):
		 	labels.append("seven")
		for i in xrange(numImages):
		    labels.append("eight")
		for i in xrange(numImages):
		 	labels.append("nine")

		# run test
		maxEpochs = 1000
		epochsPerSave = 5

		self.net.trainSet(data, labels, maxEpochs, epochsPerSave)
		self.net.testSet(data, labels)
		self.net.saveFilters(1010)
		self.net.saveActivations(1010)