importtorch# 2D (T, 17, 2) -> 3D (T, 17, 3) via temporal CNNclassTemporalLift(torch.nn.Module):def__init__(self,n_kpts=17,ch=1024):super().__init__()self.expand=torch.nn.Conv1d(n_kpts*2,ch,3,padding=1)self.blocks=torch.nn.Sequential(*[torch.nn.Sequential(torch.nn.Conv1d(ch,ch,3,padding=1,dilation=d),torch.nn.BatchNorm1d(ch),torch.nn.ReLU())fordin(3,9,27)])self.head=torch.nn.Conv1d(ch,n_kpts*3,1)defforward(self,x):# x: (B, T, 17, 2)B,T=x.shape[:2]x=x.reshape(B,T,-1).transpose(1,2)returnself.head(self.blocks(self.expand(x))).transpose(1,2).reshape(B,T,-1,3)
COCO keypoint metric (OKS / mAP)
frompycocotools.cocoimportCOCOfrompycocotools.cocoevalimportCOCOevalgt=COCO('person_keypoints_val2017.json')dt=gt.loadRes('predictions.json')e=COCOeval(gt,dt,'keypoints')e.evaluate();e.accumulate();e.summarize()# AP @ OKS=.50:.95 — 표준 metric