-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
45 lines (38 loc) · 1.18 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import numpy as numpy
from features import calculateFeatures
from classifier import calculateCluster
from sklearn.datasets import load_digits
from sklearn.preprocessing import scale
import sys
def fillFeaturesMatrix (paintings):
paintingFeatures = numpy.array([])
for painting in paintings:
features = calculateFeatures(painting)
if paintingFeatures.size == 0:
paintingFeatures = features
else:
paintingFeatures = numpy.vstack((paintingFeatures, features))
sys.stdout.write('.')
sys.stdout.flush()
print
return paintingFeatures
## Creating array of labels and directories to calculate features
painters = []
paintings = []
directory = "paintings"
for folder in os.listdir(directory):
folderRoute = os.path.join(directory, folder)
if os.path.isdir(folderRoute):
for fileName in os.listdir(folderRoute):
if not fileName.startswith('.'):
painters.append(folder)
paintings.append(os.path.join(folderRoute, fileName))
paintersArray = numpy.array([painters])
featuresMatrix = fillFeaturesMatrix(paintings)
#digits = load_digits()
#data = scale(digits.data)
#digits = digits.target
data = scale(featuresMatrix)
digits = painters
calculateCluster (data, digits)