Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

量化导入自己pth模型时候出现 KeyError: 'state_dict' #95

Open
maziyi234 opened this issue Nov 18, 2021 · 1 comment
Open

量化导入自己pth模型时候出现 KeyError: 'state_dict' #95

maziyi234 opened this issue Nov 18, 2021 · 1 comment

Comments

@maziyi234
Copy link

(pytorch1) maziyi@kpyf:~/python/yolox5/micronet/micronet/compression/quantization/wqaq/iao$ python main.py --resume "/home/maziyi/python/yolox5/yolox_best.pth" --q_type 0 --q_level 0 --bn_fuse --qaft --lr 0.00001
==> Options: Namespace(a_bits=8, batch_size=32, bn_fuse=True, bn_fuse_calib=False, cpu=False, data='../../../../data', end_epochs=300, eval_batch_size=32, gpu_id='', lr='0.00001', model_type=1, num_workers=2, percentile=0.999999, pretrained_model=False, prune_qaft='', prune_quant='', ptq=False, ptq_batch=200, ptq_control=False, q_level=0, q_type=0, qaft=True, refine='', resume='/home/maziyi/python/yolox5/yolox_best.pth', start_epochs=1, w_bits=8, wd=1e-05, weight_observer=0)
==> Preparing data..
Files already downloaded and verified
Files already downloaded and verified
Reume model
ori_model
Net(
(model): Sequential(
(0): ConvBNReLU(
(conv): Conv2d(3, 256, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
(bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(1): ConvBNReLU(
(conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1), groups=2)
(bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(2): ConvBNReLU(
(conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1), groups=2)
(bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(3): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(4): ConvBNReLU(
(conv): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=16)
(bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(5): ConvBNReLU(
(conv): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1), groups=4)
(bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(6): ConvBNReLU(
(conv): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1), groups=4)
(bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(7): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(8): ConvBNReLU(
(conv): Conv2d(512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=32)
(bn): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(9): ConvBNReLU(
(conv): Conv2d(1024, 1024, kernel_size=(1, 1), stride=(1, 1), groups=8)
(bn): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(10): ConvBNReLU(
(conv): Conv2d(1024, 10, kernel_size=(1, 1), stride=(1, 1))
(bn): BatchNorm2d(10, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace=True)
)
(11): AvgPool2d(kernel_size=8, stride=1, padding=0)
)
)

quant_model
Net(
(model): Sequential(
(0): ConvBNReLU(
(conv): QuantBNFuseConv2d(
3, 256, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2)
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(1): ConvBNReLU(
(conv): QuantBNFuseConv2d(
256, 256, kernel_size=(1, 1), stride=(1, 1), groups=2
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(2): ConvBNReLU(
(conv): QuantBNFuseConv2d(
256, 256, kernel_size=(1, 1), stride=(1, 1), groups=2
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(3): QuantMaxPool2d(
kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
)
(4): ConvBNReLU(
(conv): QuantBNFuseConv2d(
256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=16
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(5): ConvBNReLU(
(conv): QuantBNFuseConv2d(
512, 512, kernel_size=(1, 1), stride=(1, 1), groups=4
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(6): ConvBNReLU(
(conv): QuantBNFuseConv2d(
512, 512, kernel_size=(1, 1), stride=(1, 1), groups=4
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(7): QuantMaxPool2d(
kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
)
(8): ConvBNReLU(
(conv): QuantBNFuseConv2d(
512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=32
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(9): ConvBNReLU(
(conv): QuantBNFuseConv2d(
1024, 1024, kernel_size=(1, 1), stride=(1, 1), groups=8
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(10): ConvBNReLU(
(conv): QuantBNFuseConv2d(
1024, 10, kernel_size=(1, 1), stride=(1, 1)
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
(weight_quantizer): SymmetricQuantizer(
(observer): MinMaxObserver()
)
)
(bn): Identity()
(relu): ReLU(inplace=True)
)
(11): QuantAvgPool2d(
kernel_size=8, stride=1, padding=0
(activation_quantizer): SymmetricQuantizer(
(observer): MovingAverageMinMaxObserver()
)
)
)
)
Traceback (most recent call last):
File "main.py", line 479, in
model.load_state_dict(checkpoint["state_dict"])
KeyError: 'state_dict'
求大佬解答

@250zhanghu
Copy link

加载出问题了,先定义自己的模型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants