根据给定的scale和zero points,把每个通道量化,返回张量 参数
input(Tensor):需要量化的浮点张量scales(Tensor):一维张量,给每个通道指定scale,大小是input.size(axis)zero_points(Tensor):size是input.size(axis)dtype例子 >>> x = torch.tensor([[-1.0, 0.0], [1.0, 2.0]]) >>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8) tensor([[-1., 0.], [ 1., 2.]], size=(2, 2), dtype=torch.quint8, quantization_scheme=torch.per_channel_affine, scale=tensor([0.1000, 0.0100], dtype=torch.float64), zero_point=tensor([10, 0]), axis=0) >>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8).int_repr() tensor([[ 0, 10], [100, 200]], dtype=torch.uint8)索引,切片,连接和转换操作torch.cat(tensors, dim=0, out=None) → Tensor指定维度,连接给定的张量,张量需要有相同的形状,或者为空也可以 参数
Tensors(Tensor序列):需要连接的张量序列dim(int,可选参数):张量连接的维度out:输出张量例子 >>> x = torch.randn(2, 3) >>> x tensor([[ 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497]]) >>> torch.cat((x, x, x), 0) tensor([[ 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497], [ 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497], [ 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497]]) >>> torch.cat((x, x, x), 1) tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497]])torch.chunk(input, chunks, dim=0) → List of Tensors把张量分割成指定数量的块,每个块是输入张量的view 最后一个块如果张量沿着指定的维度不可分割成指定形状的块,那么最后一个块形状更小 参数
input(Tensor):需要分割的张量chunks(int):需要返回的块数量dim(int):沿分割的维度torch.gather(input, dim, index, out=None, sparse_grad=False) → Tensor沿给定的维度轴,收集值 对于一个三维张量:
out[i][j][k] = input[index[i][j][k]][j][k] # 如果 dim == 0 out[i][j][k] = input[i][index[i][j][k]][k] # 如果 dim == 1 out[i][j][k] = input[i][j][index[i][j][k]] # 如果 dim == 2如果输入张量是n维,大小为(x0,x1,x2,...,xn-1),指定的dim为i,那么index必须是n维张量,在y>=1的地方,其大小为(x0,x1,...,xn-1),输出张量out则和index一样的size 参数
input(Tensor):源张量dim(int):索引的轴index:需要收集元素的索引outsparse_grad(bool,可选参数):如果是True,那么输入input是一个稀疏张量例子 >>> t = torch.tensor([[1,2],[3,4]]) >>> torch.gather(t, 1, torch.tensor([[0,0],[1,0]])) tensor([[ 1, 1], [ 4, 3]])torch.index_select(input, dim, index, out=None) → Tensor返回一个新的张量,沿input指定的dim索引,index是一个长张量 返回的张量和源张量维度相同,指定dim的这个维度和index一样长度,其他的维度和源张量一样 返回张量开辟新的内存,如果输出张量out的shape不适合,会自动纠正,并且必要时重新开辟内存 参数
input(Tensor):输入张量dim(int):我们需要索引的维度index(LongTensor):包含需要索引的序列out例子 >>> x = torch.randn(3, 4) >>> x tensor([[ 0.1427, 0.0231, -0.5414, -1.0009], [-0.4664, 0.2647, -0.1228, -1.1068], [-1.1734, -0.6571, 0.7230, -0.6004]]) >>> indices = torch.tensor([0, 2]) >>> torch.index_select(x, 0, indices) tensor([[ 0.1427, 0.0231, -0.5414, -1.0009], [-1.1734, -0.6571, 0.7230, -0.6004]]) >>> torch.index_select(x, 1, indices) tensor([[ 0.1427, -0.5414], [-0.4664, -0.1228], [-1.1734, 0.7230]]) ---来自腾讯云社区的---Rare0716
微信扫一扫打赏
支付宝扫一扫打赏