def cat(tensors, dim=0): """ Efficient version of torch.cat that avoids a copy if there is only a single element in a list """ """ 重写了cat函数,使得当传入的张量只有一个元素的时候避免做拼接操作,只有可拼接的情况下,即有多个元素的情况下进行拼接 """ assert isinstance(tensors, (list, tuple)) if len(tensors) == 1: return tensors[0] return torch.cat(tensors, dim)
文章来源: https://blog.csdn.net/leijieZhang/article/details/90909781