class MinWTFeedbackEdgeSet: def __init__(self, g): self.edge_set = [] self.g = g self.heap = MaxHeap() self.UF = UnionFind(g.V) self.populateHeap() self.populate_edge_set() def populateHeap(self): edges = set() for i in range(self.g.V): for edge in self.g.adj(i): edges.add(edge) for edge in edges: self.heap.add_item(edge) def populate_edge_set(self): #import pdb; pdb.set_trace() while not self.heap.empty(): edge = self.heap.del_max() if not self.UF.find(edge.either(), edge.other(edge.either())): self.UF.union(edge.either(), edge.other(edge.either())) else: self.edge_set.append(edge) def get_mst(self): return self.edge_set
def decodeMultiplePoses( scores, offsets, displacementsFwd, displacementsBwd, width_factor, height_factor, outputStride=16, maxPoseDetections=5, scoreThreshold=0.5, nmsRadius=30, ): poses = [] squaredNmsRadius = nmsRadius * nmsRadius scoresBuffer = np.squeeze(scores) offsetsBuffer = np.squeeze(offsets) displacementsBwdBuffer = np.squeeze(displacementsBwd) displacementsFwdBuffer = np.squeeze(displacementsFwd) height, width, numKeypoints = scoresBuffer.shape queue = MaxHeap(height * width * numKeypoints, scoresBuffer) buildPartWithScoreQueue(scoreThreshold, kLocalMaximumRadius, scoresBuffer, queue) while len(poses) < maxPoseDetections and queue.empty() is False: root = queue.dequeue() rootImageCoords = getImageCoords(root["part"], outputStride, offsetsBuffer) if (withinNmsRadiusOfCorrespondingPoint( poses, squaredNmsRadius, rootImageCoords, root["part"]["id"]) is True): continue # Start a new detection instance at the position of the root. keypoints = decodePose( root, scoresBuffer, offsetsBuffer, outputStride, displacementsFwdBuffer, displacementsBwdBuffer, ) for keypoint in keypoints: keypoint["position"]["y"] *= height_factor keypoint["position"]["x"] *= width_factor score = getInstanceScore(poses, squaredNmsRadius, keypoints) poses.append({"keypoints": keypoints, "score": score}) return poses
def decodeMultiplePoses(scores, offsets, displacementsFwd, displacementsBwd, \ width_factor, height_factor, \ outputStride=16, maxPoseDetections=5, scoreThreshold= 0.5, nmsRadius= 30): poses = [] squaredNmsRadius = nmsRadius * nmsRadius scoresBuffer = np.squeeze(scores) offsetsBuffer = np.squeeze(offsets) displacementsBwdBuffer = np.squeeze(displacementsBwd) displacementsFwdBuffer = np.squeeze(displacementsFwd) height, width, numKeypoints = scoresBuffer.shape queue = MaxHeap(height * width * numKeypoints, scoresBuffer) buildPartWithScoreQueue(scoreThreshold, kLocalMaximumRadius, scoresBuffer, queue) while len(poses) < maxPoseDetections and queue.empty() is False: root = queue.dequeue() rootImageCoords = getImageCoords(root['part'], outputStride, offsetsBuffer) if withinNmsRadiusOfCorrespondingPoint(poses, \ squaredNmsRadius, \ rootImageCoords, \ root['part']['id']) is True: continue #Start a new detection instance at the position of the root. keypoints = decodePose(root, \ scoresBuffer, \ offsetsBuffer, \ outputStride, \ displacementsFwdBuffer, \ displacementsBwdBuffer) for keypoint in keypoints: keypoint['position']['y'] *= (height_factor) keypoint['position']['x'] *= (width_factor) score = getInstanceScore(poses, squaredNmsRadius, keypoints) poses.append({'keypoints': keypoints, 'score': score}) return poses