Documente Academic
Documente Profesional
Documente Cultură
/usr/bin/python
#Copyright 2015 CVC-UAB
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
import Config as cfg
import pickle
from sklearn import svm
from sklearn import linear_model
import os
def loadImageFeatures(featuresPath):
print 'Loading features from '+str(featuresPath)
file = open(featuresPath, 'r')
return pickle.load(file)
def run():
#List all the files .feat in the positives directory
positiveList = os.listdir(cfg.positiveFeaturesPath)
positiveList = filter(lambda element: '.feat' in element, positiveList)
#Load the features of the first element, to obtain the size of the feature
vectors.
filepath = cfg.positiveFeaturesPath + '/'+positiveList[0]
file = open(filepath, 'r')
feats = pickle.load(file)
featuresLength = len(feats)
#Initialize the structure that we will pass to the model for training
# X will be the samples for training
# y will be the labels
X = np.zeros(shape=(samplesCount, featuresLength))
y = np.append(np.ones(shape=(1, positiveSamplesCount)),
-1*np.ones(shape=(1, negativeSamplesCount)))
model.fit(X, y)
#Obtain the model score for the training set
print 'MODEL score'
print model.score(X, y)
if __name__ == '__main__':
run()