From 864d7f969a096518b8c987b752231da3390c11f3 Mon Sep 17 00:00:00 2001 From: xsl Date: Thu, 9 Jul 2026 23:44:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20torch.load=20=E6=B7=BB=E5=8A=A0=20weight?= =?UTF-8?q?s=5Fonly=3DFalse=20=E4=BB=A5=E5=85=BC=E5=AE=B9=E6=96=B0?= =?UTF-8?q?=E7=89=88=20PyTorch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- face_analysis/bisenet_model.py | 2 +- face_analysis/hair_segmenter.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/face_analysis/bisenet_model.py b/face_analysis/bisenet_model.py index aa224dd..cfed71a 100644 --- a/face_analysis/bisenet_model.py +++ b/face_analysis/bisenet_model.py @@ -79,7 +79,7 @@ class Resnet18(nn.Module): def init_weight(self): # 优先本地骨干权重(内网离线),缺失才回退 torch model_zoo(会查缓存)。 if os.path.isfile(_LOCAL_RESNET18): - state_dict = torch.load(_LOCAL_RESNET18, map_location="cpu") + state_dict = torch.load(_LOCAL_RESNET18, map_location="cpu", weights_only=False) else: state_dict = modelzoo.load_url(resnet18_url) self_state_dict = self.state_dict() diff --git a/face_analysis/hair_segmenter.py b/face_analysis/hair_segmenter.py index ff2c05f..f0ce40a 100644 --- a/face_analysis/hair_segmenter.py +++ b/face_analysis/hair_segmenter.py @@ -52,7 +52,7 @@ class HairSegmenter: self._torch = torch self.device = _select_device(torch) self.net = BiSeNet(n_classes=N_CLASSES) - state = torch.load(weights_path, map_location="cpu") + state = torch.load(weights_path, map_location="cpu", weights_only=False) self.net.load_state_dict(state) self.net.to(self.device) self.net.eval()