cxzhou95 / XLSR

PyTorch implementation of paper "Extremely Lightweight Quantization Robust Real-Time Single-Image Super Resolution for Mobile Devices"
MIT License
56 stars 9 forks source link

量化后模型输出问题 #5

Closed Cliveliew closed 2 years ago

Cliveliew commented 2 years ago

您好!我在将您给的best模型PTQ量化以后,测试了自己的图片。结果输出的图像数据数值不是0就是255,请问这是怎么回事呢?感谢您的解答!

Cliveliew commented 2 years ago

稍微改了一下,输出数据倒不是只有0/255了,但是量化模型的效果差距比较大,请问这样的差距正常吗? img_48 img_48_

cxzhou95 commented 2 years ago

看起来不正常,你是在你的数据上量化训练的吗?还是和我一样的数据DIV2K?如果不一样,数据的退化模型一样吗?退化模型不一样的话要重新训练float 模型再做量化。

Cliveliew @.***>于2021年11月25日 周四下午5:47写道:

稍微改了一下,输出数据倒不是只有0/255了,但是量化模型的效果差距比较大,请问这样的差距正常吗? [image: img_48] https://user-images.githubusercontent.com/55566805/143418305-6962f110-7041-4590-b68a-f2c5593d2840.png [image: img48] https://user-images.githubusercontent.com/55566805/143418319-496b9347-28da-4045-9ea5-3ef2f5124683.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cxzhou95/XLSR/issues/5#issuecomment-979040074, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIHI4L4ZX3BVQ2V2F32NFX3UNYA45ANCNFSM5IX36CGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Cliveliew commented 2 years ago

这是我用您的best.qt模型量化后随便找了张图测试的,测试图没有用退化模型处理,上图是量化后的输出,下图是原模型的输出; 我还用自己的数据集训了您的原网络(没有加载您的best.pt模型,非QAT训练,就只是原float的训练),最后的模型效果很好,但是量化后也有问题。

cxzhou95 commented 2 years ago

除了best.pt我还上传了其他两个模型,一个是PTQ量化,一个是QAT量化,你测试看看。

Cliveliew @.***>于2021年11月25日 周四下午5:58写道:

这是我用您的best.qt模型量化后随便找了张图测试的,测试图没有用退化模型处理,上图是量化后的输出,下图是原模型的输出; 我还用自己的数据集训了您的原网络(没有加载您的best.pt模型,非QAT训练,就只是原float的训练),最后的模型效果很好,但是量化后也有问题。

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/cxzhou95/XLSR/issues/5#issuecomment-979047836, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIHI4L2XNYNENTE5Z5GAWKLUNYCD7ANCNFSM5IX36CGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Cliveliew commented 2 years ago

感谢您的回复!我把我的torch版本换成了和您一致的,尝试了您的QTSQ和QAT模型,运行正常且效果很好。我怀疑是否是我的量化转换代码写漏了,因为看了您的代码和网上的博客但是没有找到问题所在,不知能否麻烦您看看转换代码是否有问题… 以下是我的转换代码: torch.manual_seed(191009) device = 'cpu' a = torch.load('exp/OneCyclicLR/best.pt', map_location=device) model = XLSR_quantization(3) model.load_state_dict(a) model.to(device) model.fuse_model()

model.qconfig = torch.quantization.get_default_qconfig('fbgemm') torch.quantization.prepare(model, inplace=True) quantized_model = torch.quantization.convert(model.eval(), inplace=False) quantized_model.eval()

Cliveliew commented 2 years ago

应该知道问题在哪了,好像prepare之后得输入点数据给模型跑跑- -