Exemplo n.º 1
0
	def test_experimental(self):
		recognizer = Recognizer()
		recognizer.load_data([
			# 'BLACK', 'BLUE', 'BROWN', 'GREEN',
			# 'PINK', 'WHITE', 'YELLOW',
			# 'CONE', 'MAPSCROLL', 'STONE',
			# 'NA',
			'BASE',
			'FLOWER', 'JAIL', 'SNOW',
			'STRIPE_1', 'STRIPE_2', 'STRIPE_3',
			'TRI',
		])
		recognizer.model = [RecognizerFlatten(), RecognizerSplit(), RecognizerPCA(), RecognizerLDA(), RecognizerSVM()]
		result = []
    # for n_pca in [10, 50, 80, 100, 150, 200, 300, 500, 700]:
		for n_pca in [150]:
      # for n_lda in [1, 3, 5, 7, 10, 15, 30, 50, 70, 100, 130, 200, 250, 300]:
			for n_lda in [15]:
				recognizer.model[1].n_components = n_pca
				recognizer.model[2].n_components = n_lda
				n = 10
				score = []
				for i in range(n):
					recognizer.fit()
					score.append(recognizer.score())
				avg = float(sum(score)) / n
				import sys
				print {'n_pca': n_pca, 'n_lda': n_lda, 'score': avg}
				result.append({'n_pca': n_pca, 'n_lda': n_lda, 'score': avg})
		import sys
		print result
		recognizer.model[1].n_components = 75
		recognizer.model[2].n_components = 30
		self.assertGreater(recognizer.score(), 0.5)
Exemplo n.º 2
0
 def test_experimental(self):
     recognizer = Recognizer()
     recognizer.load_data([
         'BASE',
         'FLOWER',
         'JAIL',
         'SNOW',
         'STRIPE_1',
         'STRIPE_2',
         'STRIPE_3',
         'TRI',
     ])
     recognizer.model = [
         RecognizerFlatten(),
         RecognizerSplit(),
         RecognizerPCA(),
         RecognizerLDA(),
         RecognizerSVM()
     ]
     recognizer.model[1].n_components = 80
     recognizer.model[2].n_components = 10
     recognizer.fit()
     recognizer.model[1].n_components = 75
     recognizer.model[2].n_components = 30
     self.assertGreater(recognizer.score(), 0.3)
Exemplo n.º 3
0
 def test_fit_predict_with_Split_PCA_SVM(self):
     self.subject.load_data(['BLACK', 'BLUE'])
     self.subject.model = [
         RecognizerFlatten(),
         RecognizerSplit(),
         RecognizerPCA(),
         RecognizerSVM()
     ]
     self.subject.fit()
     self.subject.score()
Exemplo n.º 4
0
    def test_basic_usage(self):
        model_filename = 'tmp/basic_usage.pkl'
        recognizer = Recognizer()
        recognizer.load_data([
            'BLACK',
            'BLUE',
            'BROWN',
            'GREEN',
            'PINK',
            'WHITE',
            'YELLOW',
            'CONE',
            'MAPSCROLL',
            'STONE',
            'NA',
        ])
        recognizer.model = [
            RecognizerFlatten(),
            RecognizerSplit(),
            RecognizerPCA(),
            RecognizerSVM()
        ]
        recognizer.fit()
        self.assertGreater(recognizer.score(), 0.9)
        recognizer.clear()
        recognizer.dump(model_filename)

        recognizer = Recognizer()
        recognizer.load(model_filename)
        data = Data()
        data.load_data([
            'BLACK',
            'BLUE',
            'BROWN',
            'GREEN',
            'PINK',
            'WHITE',
            'YELLOW',
            'CONE',
            'MAPSCROLL',
            'STONE',
            'NA',
        ])
        self.assertGreater(recognizer.score(data), 0.97)
Exemplo n.º 5
0
	def test_basic_usage(self):
		self.subject = Recognizer()
		# self.subject.load_data([
		# 	'BLACK', 'BLUE', 'BROWN', 'GREEN',
		# 	'PINK', 'WHITE', 'YELLOW',
		# 	'CONE', 'MAPSCROLL', 'STONE',
		# 	'NA',
		# ])
		self.subject.load_data([
			'BASE',
			'FLOWER', 'JAIL', 'SNOW',
			'STRIPE_1', 'STRIPE_2', 'STRIPE_3',
			'TRI',
		])
		self.subject.model = [RecognizerSplit(), RecognizerDL()]
		self.subject.model[-1].batch_size = 128
		self.subject.model[-1].conv1_filter = 2
		self.subject.model[-1].conv1_size = 3
		self.subject.model[-1].conv1_dropout= 0.25
		self.subject.model[-1].conv2_filter = 2
		self.subject.model[-1].conv2_size = 3
		self.subject.model[-1].conv2_dropout= 0.25
		self.subject.model[-1].dimof_middle = 1
		self.subject.model[-1].dropout = 0.5
		self.subject.model[-1].countof_epoch = 1
		self.subject.model[-1].verbose = 1
		self.subject.fit()
		score1 = self.subject.model[-1].score(self.subject.data)

		model_filename = 'tmp/test_model'
		self.subject.model[-1].dump(model_filename)
		self.subject = RecognizerDL()
		self.subject.load(model_filename)
		self.subject.load_data([
			'BASE',
			'FLOWER', 'JAIL', 'SNOW',
			'STRIPE_1', 'STRIPE_2', 'STRIPE_3',
			'TRI',
		])
		score2 = self.subject.score(self.subject.data)

		self.assertEqual(score1, score2)
Exemplo n.º 6
0
class RecognizerSplitTest(unittest.TestCase):
    def setUp(self):
        self.original_base = ImageReader.base
        ImageReader.base = 'tests/fixtures/' + ImageReader.base

        self.subject = RecognizerSplit()

    def tearDown(self):
        ImageReader.base = self.original_base

    def test_fit(self):
        self.subject.load_data(['BLACK', 'BLUE'])
        self.subject.fit()

    def test_transform(self):
        self.subject.load_data(['BLACK', 'BLUE'])
        data = self.subject.transform()
        self.assertEqual(len(data.X), len(data.y))
        self.assertEqual(len(data.X), 12)
        self.assertEqual(len(self.subject.test_data.X),
                         len(self.subject.test_data.y))
        self.assertEqual(len(self.subject.test_data.X), 3)
Exemplo n.º 7
0
class RecognizerSplitTest(unittest.TestCase):
	def setUp(self):
		self.original_base = ImageReader.base
		ImageReader.base = 'tests/fixtures/' + ImageReader.base

		self.subject = RecognizerSplit()

	def tearDown(self):
		ImageReader.base = self.original_base

	def test_fit(self):
		self.subject.load_data(['BLACK', 'BLUE'])
		self.subject.fit()

	def test_transform(self):
		self.subject.load_data(['BLACK', 'BLUE'])
		data = self.subject.transform()
		self.assertEqual(len(data.X), len(data.y))
		self.assertEqual(len(data.X), 12)
		self.assertEqual(
			len(self.subject.test_data.X),
			len(self.subject.test_data.y))
		self.assertEqual(len(self.subject.test_data.X), 3)
Exemplo n.º 8
0
	def setUp(self):
		self.original_base = ImageReader.base
		ImageReader.base = 'tests/fixtures/' + ImageReader.base

		self.subject = RecognizerSplit()
Exemplo n.º 9
0
    def setUp(self):
        self.original_base = ImageReader.base
        ImageReader.base = 'tests/fixtures/' + ImageReader.base

        self.subject = RecognizerSplit()