自定义#

from mod import load_mod
# 载入自定义模块
load_mod()

from pytorch_book.quantization.qat import QuantizableCustom
from xinet import CV
qat = QuantizableCustom('resnet18')
model = qat.qconfig(quantize=True,
                    pretrained=True,
                    progress=True)
batch_size = 128
train_iter, test_iter = CV.load_data_cifar10(batch_size=batch_size)
quantized_model = model.quantize_qat(model,
                                     run_fn=CV.train_fine_tuning,
                                     run_args=[train_iter, test_iter],
                                     run_kwargs={
                                         'learning_rate': 1e-3,
                                         'num_epochs': 100,
                                     },
                                     inplace=False
                                     )
Files already downloaded and verified
Files already downloaded and verified
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb Cell 5' in <cell line: 3>()
      <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=0'>1</a> batch_size = 128
      <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=1'>2</a> train_iter, test_iter = CV.load_data_cifar10(batch_size=batch_size)
----> <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=2'>3</a> quantized_model = model.quantize_qat(model,
      <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=3'>4</a>                                      run_fn=CV.train_fine_tuning,
      <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=4'>5</a>                                      run_args=[train_iter, test_iter],
      <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=5'>6</a>                                      run_kwargs={
      <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=6'>7</a>                                          'learning_rate': 1e-3,
      <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=7'>8</a>                                          'num_epochs': 100,
      <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=8'>9</a>                                      },
     <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=9'>10</a>                                      inplace=False
     <a href='vscode-notebook-cell://ssh-remote%2B10.16.11.3/media/pc/data/4tb/xinet/web/pytorch-book/docs/quantization/study/transfer-learning/custom.ipynb#ch0000011vscode-remote?line=10'>11</a>                                      )

File ~/xinet/anaconda3/envs/torchx/lib/python3.10/site-packages/torch/nn/modules/module.py:1185, in Module.__getattr__(self, name)
   <a href='file:///home/pc/xinet/anaconda3/envs/torchx/lib/python3.10/site-packages/torch/nn/modules/module.py?line=1182'>1183</a>     if name in modules:
   <a href='file:///home/pc/xinet/anaconda3/envs/torchx/lib/python3.10/site-packages/torch/nn/modules/module.py?line=1183'>1184</a>         return modules[name]
-> <a href='file:///home/pc/xinet/anaconda3/envs/torchx/lib/python3.10/site-packages/torch/nn/modules/module.py?line=1184'>1185</a> raise AttributeError("'{}' object has no attribute '{}'".format(
   <a href='file:///home/pc/xinet/anaconda3/envs/torchx/lib/python3.10/site-packages/torch/nn/modules/module.py?line=1185'>1186</a>     type(self).__name__, name))

AttributeError: 'QuantizableResNet' object has no attribute 'quantize_qat'