现在位置: 首页 > PyTorch 教程 > 正文

PyTorch torch.dequantize 函数


Pytorch torch 参考手册 Pytorch torch 参考手册

torch.dequantize 是 PyTorch 中用于将量化张量反量化为浮点张量的函数。

函数定义

torch.dequantize(input)

使用示例

实例

import torch

# 创建输入张量
input = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])

# 量化张量
quantized = torch.quantize_per_tensor(input, scale=0.1, zero_point=10, dtype=torch.quint8)

print("量化张量:")
print(quantized)

# 反量化
x = torch.dequantize(quantized)

print("反量化后的浮点张量:")
print(x)

Pytorch torch 参考手册 Pytorch torch 参考手册