def train(self, trainSet): pntNum = trainSet.meanShape.shape[0] treeNum = int(self.maxTreeNum / pntNum) # Train the random forests for i in range(pntNum): rf = RandForest(treeDepth=self.treeDepth, treeNum=treeNum, feaNum=self.feaNum, radius=self.radius, binNum=self.binNum, feaRange=self.feaRange) rf.train(trainSet, i) self.rfs.append(rf) # Extract the local binary features feas = self.genFeaOnTrainset(trainSet) # Global regression y = trainSet.residuals y = y.reshape(y.shape[0], y.shape[1] * y.shape[2]) for i in range(pntNum * 2): # TODO Show the training result reg = LinearSVR(epsilon=0.0, C=1.0 / feas.shape[0], loss='squared_epsilon_insensitive', fit_intercept=True) reg.fit(feas, y[:, i]) self.regs.append(reg) # Update the initshapes for i in range(pntNum): regX = self.regs[2 * i] regY = self.regs[2 * i + 1] x = regX.predict(feas) y = regY.predict(feas) delta = np.squeeze(np.dstack((x, y))) delta = Affine.transPntsForwardWithDiffT(delta, trainSet.ms2reals) delta = np.multiply(delta, trainSet.bndBoxs[:, [2, 3]]) trainSet.initShapes[:, i, :] = trainSet.initShapes[:, i, :] + delta