-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_hlf_cache.py
58 lines (44 loc) · 1.79 KB
/
generate_hlf_cache.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
53
54
55
56
#!/usr/bin/env python
"""
Generate a cache of all the
"""
from __future__ import division
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/scratch/s1145806/cached_hlf_train_data_raw.pkl'
pkl_path2 = '/disk/scratch/s1145806/cached_hlf_train_raw.pkl'
pkl_path3 = '/disk/scratch/s1145806/cached_hlf_train_data_ranged.pkl'
pkl_path4 = '/disk/scratch/s1145806/cached_hlf_train_ranged.pkl'
pkl_path5 = '/disk/scratch/s1145806/cached_hlf_train_data_posranged.pkl'
pkl_path6 = '/disk/scratch/s1145806/cached_hlf_train_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, settings.classes)
# Combine all the features we want to use
hlf = neukrill_net.highlevelfeatures.BasicAttributes(attrlst)
hlf += neukrill_net.highlevelfeatures.ContourMoments()
hlf += neukrill_net.highlevelfeatures.ContourHistogram()
hlf += neukrill_net.highlevelfeatures.ThresholdAdjacency()
hlf += neukrill_net.highlevelfeatures.ZernikeMoments()
hlf += neukrill_net.highlevelfeatures.Haralick()
# hlf += neukrill_net.highlevelfeatures.CoocurProps()
# Save the raw values of every feature
X_raw = hlf.generate_cache(X)
hlf_raw = copy.deepcopy(hlf)
# Save the feature matrix to disk
joblib.dump(X_raw, pkl_path1)
# the [-1,1] squashed values
X_range = X / np.amax(np.absolute(X),0)
# Save the feature matrix
joblib.dump(X_range, pkl_path3)
# the [0,1] squashed values
X_posrange = (X-X.min(0))/(X.max(0)-X.min(0))
# Save the feature matrix
joblib.dump(X_posrange, pkl_path5)