Beispiel #1
0
 def __init__(self, model_path):
     self.model = bodypose_model()
     if torch.cuda.is_available():
         self.model = self.model.cuda()
     model_dict = util.transfer(self.model, torch.load(model_path))
     self.model.load_state_dict(model_dict)
     self.model.eval()
    def __init__(self, model_path, add_model_path, add=True):
        self.model = bodypose_model()
        if torch.cuda.is_available():
            self.model = self.model.cuda()
        model_dict = util.transfer(self.model, torch.load(model_path))
        self.model.load_state_dict(model_dict)
        self.model.eval()

        if add:
            self.add_model = add_model()
            if torch.cuda.is_available():
                self.add_model = self.add_model.cuda()
            add_model_dict = util.add_transfer(
                self.add_model, torch.load(
                    add_model_path))  #,  map_location=torch.device('cpu')))
            self.add_model.load_state_dict(add_model_dict)
            # self.add_model.load_state_dict(torch.load(add_model_path))
            self.add_model.eval()
inWidth = 368
inHeight = 368
thr = 0.1

import torch
from src import util

torchmodelfile = 'model/body_pose_model.pth'
from src.model import bodypose_model
torchnet = bodypose_model()
if torch.cuda.is_available():
    torchmodel = torchnet.cuda()
else:
    torchmodel = torchnet.cpu()
model_dict = util.transfer(torchmodel, torch.load(torchmodelfile))
torchmodel.load_state_dict(model_dict)
torchmodel.eval()

frame = cv.imread("images/demo.jpg")

frameWidth = frame.shape[1]
frameHeight = frame.shape[0]
stride = 8
padValue = 128

#imageToTest = cv.resize(frame, (0, 0), fx=368, fy=368, interpolation=cv.INTER_CUBIC)
imageToTest = cv.resize(frame, (368, 368))

imageToTest_padded, pad = util.padRightDownCorner(imageToTest, stride,
                                                  padValue)