mask = mask_miss.expand_as(sxing).clone() # type: torch.Tensor
mask[:, :, -2, :, :] = 1 # except for person mask channel
为了避免对expand后对某个channel操作会影响原始tensor的全部元素,需要使用clone()
如果没有clone(),对mask_miss的某个通道赋值后,所有通道上的tensor都会变成1!
# Notice! expand does not allocate more memory but just make the tensor look as if you expanded it.
# You should call .clone() on the resulting tensor if you plan on modifying it
# https://discuss.pytorch.org/t/very-strange-behavior-change-one-element-of-a-tensor-will-influence-all-elements/41190