classPositionEmbeddingSine(nn.Module):"""
This is a more standard version of the position embedding, very similar to the one
used by the Attention is all you need paper, generalized to work on images.
"""def__init__(self, num_pos_feats=64, temperature=10000, normalize=False, scale=None):super().__init__()
self.num_pos_feats = num_pos_feats
self.temperature = temperature
self.normalize = normalize
if scale isnotNoneand normalize isFalse:raise ValueError("normalize should be True if scale is passed")if scale isNone:
scale =2* math.pi
self.scale = scale
N_steps =128
position_embedding = PositionEmbeddingSine(N_steps, normalize=True)# N_steps 赋值给 num_pos_feats