本文整理汇总了Python中FileIO.saveTraining方法的典型用法代码示例。如果您正苦于以下问题:Python FileIO.saveTraining方法的具体用法?Python FileIO.saveTraining怎么用?Python FileIO.saveTraining使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileIO
的用法示例。
在下文中一共展示了FileIO.saveTraining方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trainSVM
# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import saveTraining [as 别名]
def trainSVM(self, numclass, numfull, numpartial):
"""The trainer function"""
fio = FileIO()
normalProb = []
import os
path = self.trainingAdress + self.name
#Check if the save directory exists
if not os.path.exists(path):
os.mkdir(path)
import imp
try:
imp.find_module('pycuda')
found = True
except ImportError:
found = False
#For every group
for i in range(len(self.files)):
#Get k for this group
k = self.klist[i]
#Saving name for the specific group
trainingName = '%s_%i__CFPK_%i_%i_%i_%i' % ('training',i, numclass, numfull, numpartial, k)
trainingpath = path +'/'+ trainingName
#Get features for this group
features, isFull, classId, names, folderlist = self.getFeatures(i,numclass,numfull,numpartial,self.getTrainingDataFrom)
#Get clusters for this group
if not found:
if(self.debugMode):
print "--------Training is Done With NORMAL CKMEANS--------"
from complexCKMeans import *
ckmeans = ComplexCKMeans(features, isFull, classId, k = k)
kmeansoutput = ckmeans.getCKMeans()
else:
if(self.debugMode):
print "--------Training is Done With CUDA--------"
from complexcudackmeans import *
clusterer = complexCudaCKMeans(features, k, classId, isFull) # FEATURES : N x 720
clusters, centers = clusterer.cukmeans()
kmeansoutput = [clusters, centers]
#Train svm in this group
trainer = Trainer(kmeansoutput, classId, features)
heteClstrFeatureId, heteClstrId = trainer.getHeterogenousClusterId()
trainer.trainSVM(heteClstrFeatureId, trainingpath)
fio.saveTraining(names, classId, isFull, features, kmeansoutput,
trainingpath, trainingName)
#NOW CALCULATE THE CENTER OF THE GROUP
nowCenter = np.zeros(len(features[0]))
totalNumOfInstances = len(features)
for cluster in kmeansoutput[0]:
for instance in cluster:
nowCenter += features[instance]
nowCenter = nowCenter/totalNumOfInstances
#SAVE THE CENTER
fio.saveOneFeature(trainingpath +'/' + str(i) + "__Training_Center_",nowCenter)
#Add total num of instances for calculating normalprob
normalProb.append(totalNumOfInstances)
#NOW CREATE Normal PROB
kj = 0
for i in normalProb:
kj += i
for i in range(len(normalProb)):
normalProb[i] = float(normalProb[i])/kj
#Save some important stuff (MOSTLY FOR PASSING PRIORPROB to the predictor
trainingInfo = {'normalProb':normalProb, 'numclass':numclass, 'numfull':numfull, 'numpartial':numpartial, 'numTrain':len(self.files),
'files':self.files, 'klist':self.klist}
np.save(path+'/trainingInfo.npy', trainingInfo)