当前位置: 首页>>代码示例>>Python>>正文


Python FileIO.saveOneFeature方法代码示例

本文整理汇总了Python中FileIO.saveOneFeature方法的典型用法代码示例。如果您正苦于以下问题:Python FileIO.saveOneFeature方法的具体用法?Python FileIO.saveOneFeature怎么用?Python FileIO.saveOneFeature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileIO的用法示例。


在下文中一共展示了FileIO.saveOneFeature方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: trainSVM

# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import saveOneFeature [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)
开发者ID:ozymaxx,项目名称:sketchautocompletion,代码行数:87,代码来源:ParallelTrainer.py


注:本文中的FileIO.saveOneFeature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。