下载地址:git clone https://www.modelscope.cn/iic/cv_resnet50_face-detection_retinaface.git
下载的 .pt模型有104M。
使用下面的代码校验模型失败了。
import torch
import os
model_path = 'C:\\Users\\Win10\\.cache\\modelscope\\hub\\models\\iic\\cv_resnet50_face-detection_retinaface\\pytorch_model.pt'
# 使用 map_location 参数确保在 CPU 上加载模型
try:
    # 尝试作为 TorchScript 模型加载
    model = torch.jit.load(model_path, map_location=torch.device('cpu'))
    model.eval()
    print("Successfully loaded as a TorchScript model.")
except (RuntimeError, AttributeError) as e:
    print(f"Failed to load as TorchScript model: {e}")
    # 如果上述方法失败,则尝试作为普通 PyTorch 模型加载
    try:
        model = torch.load(model_path, map_location=torch.device('cpu'))
        if hasattr(model, 'eval'):
            model.eval()
            print("Successfully loaded as a regular PyTorch model.")
        else:
            print("Loaded object does not have an 'eval' method. It might be a state_dict.")
    except Exception as e:
        print(f"Failed to load as a regular PyTorch model: {e}")
错误信息:
已连接到 pydev 调试器(内部版本号 243.23654.177)Loaded object does not have an 'eval' method. It might be a state_dict.
进程已结束,退出代码为 0