关键点缩放从原点开始,而图像缩放使用半像素中心。
H, W = 65, 97 XC, YC, SIGMA = 20.25, 24.5, 3.0 y = np.arange(H)[:, None] + 0.5 x = np.arange(W)[None, :] + 0.5 blob = np.exp(-((x - XC) ** 2 + (y - YC) ** 2) / (2 * SIGMA ** 2)) image = torch.from_numpy(blob)[None].double()
def centroid(channel): h, w = channel.shape mass = channel.astype(np.float64).sum() return np.array([(channel.sum(0) * (np.arange(w) + 0.5)).sum() / mass, (channel.sum(1) * (np.arange(h) + 0.5)).sum() / mass])
print("rfdetr", version("rfdetr")) for output_size in [(94, 155), (47, 65), (85, 77)]: target = {"keypoints": torch.tensor([[[XC - 0.5, YC - 0.5, 0.5], [XC - 0.5, YC - 0.5, 0.5], [XC - 0.5, YC - 0.5, 0.5]]])} image = Resize(output_size, image, interpolation=2, align_corners=False) print("image", image.shape, "keypoints", target["keypoints"].shape) print("centroids", centroid(image), centroid(target["keypoints"]))
Environment: RF-DETR 1.10.1, torch 2.14.0, torchvision 0.29.0, Python 3.13.5, numpy 2.5.3, macOS 26.3.1 arm64.
内容来源: roboflow/rf-detr