【问题标题】:How can I get predictions from these pretrained models?如何从这些预训练模型中获得预测?
【发布时间】:2019-10-10 13:15:54
【问题描述】:

我一直在尝试生成人体姿势估计,我遇到了许多预训练模型(例如 Pose2Segdeep-high-resolution-net),但是这些模型仅包含用于训练和测试的脚本,这似乎是为实现研究论文中的模型而编写的代码,在deep-high-resolution-net 我试图编写一个脚本来加载预训练模型并将其提供给我的图像,但我得到的输出是一堆张量,我不知道如何转换它们到我需要的 .json 注释。

这里的总新手,抱歉我的英语很差,感谢任何提示。

我会包含我的脚本,但它超过 100 行。

PS:与作者联系并询问他们是否可以提供帮助是否礼貌?

因为它看起来有点令人反感。

【问题讨论】:

    标签: machine-learning computer-vision pytorch


    【解决方案1】:

    我没有做骨骼检测研究,但你的问题似乎很普遍。

    (1) 我认为其他人不应该从一开始就教你如何加载数据和运行他们的代码。

    (2) 运行其他人的代码,只需修改他们提供的测试脚本,例如

    https://github.com/leoxiaobin/deep-high-resolution-net.pytorch/blob/master/tools/test.py

    他们已经帮助您加载模型

     model = eval('models.'+cfg.MODEL.NAME+'.get_pose_net')(
            cfg, is_train=False
        )
    
        if cfg.TEST.MODEL_FILE:
            logger.info('=> loading model from {}'.format(cfg.TEST.MODEL_FILE))
            model.load_state_dict(torch.load(cfg.TEST.MODEL_FILE), strict=False)
        else:
            model_state_file = os.path.join(
                final_output_dir, 'final_state.pth'
            )
            logger.info('=> loading model from {}'.format(model_state_file))
            model.load_state_dict(torch.load(model_state_file))
    
        model = torch.nn.DataParallel(model, device_ids=cfg.GPUS).cuda()
    

    打电话就行了

    # evaluate on Variable x with testing data
    y = model(x)
    # access Variable's tensor, copy back to CPU, convert to numpy
    arr = y.data.cpu().numpy()
    # write CSV
    np.savetxt('output.csv', arr)
    

    你应该可以用excel打开它

    (3) “将它们转换为我需要的 .json 注释”。

    这是没人能解决的问题。我们不知道您想要什么格式。对于他们的格式,可以通过他们的论文获得。或者通过

    查看他们的训练数据
    X, y = torch.load('some_training_set_with_labels.pt')
    

    通过关联 x 和 y。那你应该有一个不错的主意。

    【讨论】:

      猜你喜欢
      • 2018-11-03
      • 1970-01-01
      • 2019-06-07
      • 2022-10-19
      • 1970-01-01
      • 2023-01-03
      • 2017-08-20
      • 2020-03-18
      • 2021-09-06
      相关资源
      最近更新 更多