RetinaFace下载下来的模型验证失败

下载地址: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}")

展开
收起
1452750375310896 2025-02-22 15:53:38 201 分享 版权
1 条回答
写回答
取消 提交回答
  • 错误信息:

    已连接到 pydev 调试器(内部版本号 243.23654.177)Loaded object does not have an 'eval' method. It might be a state_dict.
    
    进程已结束,退出代码为 0
    
    2025-02-22 17:13:24
    赞同 392 展开评论

包含图像分类、图像生成、人体人脸识别、动作识别、目标分割、视频生成、卡通画、视觉评价、三维视觉等多个领域

热门讨论

热门文章

还有其他疑问?
咨询AI助理