ImportError: cannot import name ‘QuantStub‘ from ‘torch.ao.quantization‘

不知道什么原因,就是找不到QuantStub这个函数,他就在DeQuantStub同一个文件中,并且这个函数是可以调用的。

解决方法

D:\ProgramData\Miniconda3\Lib\site-packages\torch\ao\quantization\__init__.py里面粘贴下面内容

class QuantStub(nn.Module):
    r"""Quantize stub module, before calibration, this is same as an observer,
    it will be swapped as `nnq.Quantize` in `convert`.

    Args:
        qconfig: quantization configuration for the tensor,
            if qconfig is not provided, we will get qconfig from parent modules
    """
    def __init__(self, qconfig=None):
        super(QuantStub, self).__init__()
        if qconfig:
            self.qconfig = qconfig

    def forward(self, x):
        return x

你可能感兴趣的:(各种环境配置,python)