Skip to content

Commit

Permalink
precomputed kernel format
Browse files Browse the repository at this point in the history
  • Loading branch information
yamins81 committed Feb 28, 2012
1 parent 52fa20a commit aff5e5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions eccv12/lfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,22 @@ def train_view2(namebases, basedirs, test=None, use_libsvm=False):

print ('Training split %d ...' % ind)
if use_libsvm:
svm, _ = train_scikits(train_Xyd_n,
if hasattr(use_libsvm, 'keys'):
kernel_choice = use_libsvm.get('kernel_choice', 'linear')
else:
kernel_choice = 'linear'
if kernel_choice == 'precomputed':
(_X, _y, _d) = train_Xyd_n
print ('Computing kernel ...')
K = np.dot(_X, _X.T)
print ('... computed kernel of shape', K.shape)
train_data = (K, _y, _d)
else:
train_data = train_Xyd_n
svm, _ = train_scikits(train_data,
labelset=[-1, 1],
model_type='svm.SVC',
model_kwargs={'kernel': 'linear'},
model_kwargs={'kernel': kernel_choice},
normalization=False
)
else:
Expand Down
10 changes: 10 additions & 0 deletions eccv12/tests/test_lfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,13 @@ def test_baby_view2_libsvm():
test=test_set)
return lfw.train_view2(['libsvm'],[os.getcwd()],
test=test_set, use_libsvm=True)


@attr('slow') #takes about 30 sec with cpu
def test_baby_view2_libsvm_kernel():
c = config_tiny_rnd0
test_set = range(20) + range(500, 520)
lfw.get_view2_features(c['slm'], c['preproc'], 'mult', 'libsvm', os.getcwd(),
test=test_set)
return lfw.train_view2(['libsvm'],[os.getcwd()],
test=test_set, use_libsvm={'kernel_choice': 'precomputed'})

0 comments on commit aff5e5e

Please sign in to comment.