chaofengc / IQA-PyTorch

👁️ 🖼️ 🔥PyTorch Toolbox for Image Quality Assessment, including LPIPS, FID, NIQE, NRQM(Ma), MUSIQ, TOPIQ, NIMA, DBCNN, BRISQUE, PI and more...
https://iqa-pytorch.readthedocs.io/
Other
1.85k stars 165 forks source link

关于从本地加载brisque_svm_weights.pth文件的问题 #193

Open xyhweinin opened 1 day ago

xyhweinin commented 1 day ago

您好! 我事先把brisque_svm_weights.pth文件下载到本地,然后想初始化时从本地加载brisque_svm_weights.pth,基本代码逻辑如下: device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") model_BRISQUE = pyiqa.create_metric('brisque', device=device) pretrained_model_path = “D:\work\VideoAI\VAS\VQCV\weights\brisque_svm_weights.pth” weights = torch.load(pretrained_model_path, map_location=device, weights_only=True) model_BRISQUE.load_state_dict(weights)

执行代码“model_BRISQUE.load_state_dict(weights)”时会异常,提示weights不是一个dict类型。 请问如何才能正确加载brisque_svm_weights.pth? 谢谢。

chaofengc commented 1 day ago

brisque 不是神经网络模型,不能用torch.load_state_dict。你可以尝试model_BRISQUE = pyiqa.create_metric('brisque', device=device, pretrained_model_path=[your/local/weight/path])

xyhweinin commented 16 hours ago

谢谢您的回复! 采用您说的那个方法确实可以加载pretrained_model_path,没有提示什么错误。但是在后面的代码中,第一次调用score_nr = self.model_BRISQUE(img_path_src)时,PyCharm的调试Console会下面的警告信息,是否会有什么影响? E:\ProgramData\anaconda3\envs\VQCV\Lib\site-packages\pyiqa\archs\brisque_arch.py:64: FutureWarning: You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature. sv_coef, sv = torch.load(pretrained_model_path)

另外,第一次调用score_nr = self.model_BRISQUE(img_path_src)时,需要的时间非常长,差不多要一分多钟,执行后面图像的分析就快很多 了,这是正常吗? 是否有提高速度的方法?

chaofengc commented 1 hour ago

警告信息不影响实际使用。

初次加载的速度问题可能是受到 load 权重的影响,后续尝试解决