-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_hlf_testcache_10aug.py
53 lines (43 loc) · 1.96 KB
/
generate_hlf_testcache_10aug.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
46
47
48
49
50
51
52
#!/usr/bin/env python
"""
Generate a cache of all the ComputerVision highlevelfeatures to send to Pylearn2
"""
from __future__ import division
import neukrill_net.augment
import neukrill_net.highlevelfeatures
import neukrill_net.utils
import copy
import numpy as np
from sklearn.externals import joblib
# Define output path
pkl_path1 = '/disk/data1/s1145806/cached_hlf_test10_data_raw.pkl'
pkl_path2 = '/disk/data1/s1145806/cached_hlf_test10_raw.pkl'
pkl_path3 = '/disk/data1/s1145806/cached_hlf_test10_data_ranged.pkl'
pkl_path4 = '/disk/data1/s1145806/cached_hlf_test10_ranged.pkl'
pkl_path5 = '/disk/data1/s1145806/cached_hlf_test10_data_posranged.pkl'
pkl_path6 = '/disk/data1/s1145806/cached_hlf_test10_posranged.pkl'
# Define which basic attributes to use
attrlst = ['height','width','numpixels','sideratio','mean','std','stderr',
'propwhite','propnonwhite','propbool']
# Parse the data
settings = neukrill_net.utils.Settings('settings.json')
X,y = neukrill_net.utils.load_rawdata(settings.image_fnames)
# Combine all the features we want to use
hlf_list = []
hlf_list.append( neukrill_net.highlevelfeatures.BasicAttributes(attrlst) )
hlf_list.append( neukrill_net.highlevelfeatures.ContourMoments() )
hlf_list.append( neukrill_net.highlevelfeatures.ContourHistogram() )
hlf_list.append( neukrill_net.highlevelfeatures.ThresholdAdjacency() )
hlf_list.append( neukrill_net.highlevelfeatures.ZernikeMoments() )
hlf_list.append( neukrill_net.highlevelfeatures.Haralick() )
# hlf_list.append( neukrill_net.highlevelfeatures.CoocurProps() )
augs = {'units': 'uint8',
'rotate': 5,
'rotate_is_resizable': 1,
'shear': [0,8]}
aug_fun = neukrill_net.augment.augmentation_wrapper(**augs)
hlf = neukrill_net.highlevelfeatures.MultiHighLevelFeature(hlf_list, augment_func=aug_fun)
# Save the raw values of every feature
X_raw = hlf.generate_cache(X)
# Save the feature matrix to disk
joblib.dump(X_raw, pkl_path1)