首页 > 解决方案 > How can I get predictions from these pretrained models?

问题描述

I've been trying to generate human pose estimations, I came across many pretrained models (ex. Pose2Seg, deep-high-resolution-net ), however these models only include scripts for training and testing, this seems to be the norm in code written to implement models from research papers ,in deep-high-resolution-net I have tried to write a script to load the pretrained model and feed it my images, but the output I got was a bunch of tensors and I have no idea how to convert them to the .json annotations that I need.

total newbie here, sorry for my poor English in advance, ANY tips are appreciated.

I would include my script but its over 100 lines.

PS: is it polite to contact the authors and ask them if they can help?

because it seems a little distasteful.

标签: machine-learningcomputer-visionpytorch

解决方案


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

(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。那么你应该有一个很好的主意。


推荐阅读