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

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

Open
xyhweinin opened this issue Oct 3, 2024 · 3 comments
Open

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

xyhweinin opened this issue Oct 3, 2024 · 3 comments

Comments

@xyhweinin
Copy link

您好! 我事先把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
Copy link
Owner

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

@xyhweinin
Copy link
Author

谢谢您的回复!
采用您说的那个方法确实可以加载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
Copy link
Owner

chaofengc commented Oct 4, 2024

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

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

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