forked from zayd/laplacian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classification.py
33 lines (25 loc) · 894 Bytes
/
classification.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
# Classification task on CIFAR
from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import LinearSVC
import laplacian
def unpickle(file):
# Open CIFAR files
import cPickle
fo = open(file, 'rb')
dict = cPickle.load(fo)
fo.close()
return dict
def classify(Phi,data='data_batch_1'):
laplacian.laplacian(images='cifar', num_images=)
# Linear Classifier in Pixel Domain
cifar = unpickle('./data/cifar-10/' + data)
X = cifar['data']
y = cifar['labels']
#pixel = OneVsRestClassifier(LinearSVC(random_state=0)).fit(X, y).predict(X)
# Load laplacian pyramid
Phi = np.load('./dictionaries/oc1-s3-t500.npy')
X = laplacian.laplacian(images='cifar')
laplacian.sparsify(X, Phi, lambdav=0.1)
pyramid = OneVsRestClassifier(LinearSVC(random_state=0)).fit(X, y).predict(X)
error = np.sum(y==prediction)/np.shape(y)[0]
return prediction