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


Python Trainer.kmeans方法代码示例

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


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

示例1: Recognizer

# 需要导入模块: from trainer import Trainer [as 别名]
# 或者: from trainer.Trainer import kmeans [as 别名]
class Recognizer(object):
    def __init__(self, vc, opts):
        self.vc = vc
        ret,im = vc.read()
        self.numGestures = opts.num
        self.imHeight,self.imWidth,self.channels = im.shape
        self.trainer = Trainer(numGestures=opts.num, numFramesPerGesture=opts.frames, minDescriptorsPerFrame=opts.desc, numWords=opts.words, descType=opts.type, kernel=opts.kernel, numIter=opts.iter, parent=self)
        self.tester = Tester(numGestures=opts.num, minDescriptorsPerFrame=opts.desc, numWords=opts.words, descType=opts.type, numPredictions=7, parent=self)

    def train_from_video(self):
        self.trainer.extract_descriptors_from_video()
        variance = self.trainer.kmeans()
        self.trainer.bow()
        score = self.trainer.svm()
        return score

    def train_from_descriptors(self, desList, trainLabels):
        self.trainer.desList = desList
        self.trainer.trainLabels = trainLabels
        #numFramesPerGesture = trainLabels.count(1)
        #self.trainer.desList = desList[:numFramesPerGesture*self.numGestures]
        #self.trainer.trainLabels = trainLabels[:numFramesPerGesture*self.numGestures]

        variance = self.trainer.kmeans()
        self.trainer.bow()
        score = self.trainer.svm()
        return score

    def train_from_images(self, gestureDirList, parentDirPath, trainMask, maskParentDirPath):
        self.trainer.extract_descriptors_from_images(gestureDirList, parentDirPath, trainMask, maskParentDirPath)
        variance = self.trainer.kmeans()
        self.trainer.bow()
        score = self.trainer.svm()
        return score

    def test_on_video(self, clf):
        #print clf.coef_
        self.tester.initialize(clf)
        self.tester.test_on_video()
    
    def test_on_descriptors(self, clf, descList, trueLabels):
        #numFramesPerGesture = trueLabels.count(1)
        #descList = descList[:numFramesPerGesture*self.numGestures]
        #trueLabels = trueLabels[:numFramesPerGesture*self.numGestures]
        self.tester.initialize(clf)
        testLabels = self.tester.test_on_descriptors(descList)
        matchList = [i for i, j in zip(trueLabels, testLabels) if i == j]
        score = float(len(matchList))/len(trueLabels)
        return score
开发者ID:arpitgit,项目名称:Talk2dHand,代码行数:51,代码来源:recognizer.py


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