-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
52 lines (36 loc) · 1.33 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import torch
import torch.nn as nn
import torch.utils.data as torch_data
import numpy as np
import json
import os
from models.cpm import CPM
from models.net import CPM_UNet
from load_data import test_OMC
from utils import show_heatmaps, get_landmarks_from_preds, visualize_result
cuda = torch.cuda.is_available()
def demo(model):
num_joints = 17
model.eval()
test_dataset = test_OMC()
test_loader = torch_data.DataLoader(test_dataset, batch_size=1, shuffle=False, \
collate_fn=test_dataset.collate_fn, num_workers=4)
for i, (img, cmap, bbox) in enumerate(test_loader):
test_img = torch.FloatTensor(img)
cmap = torch.FloatTensor(cmap)
bbox = bbox[0]
pred_heatmaps = model(test_img, cmap)
pred_hmap = pred_heatmaps[-1][0].cpu().detach().numpy().transpose((1,2,0))
img = img[0].transpose((1,2,0))
show_heatmaps(img, pred_hmap)
visualize_result(img, pred_hmap)
print(i)
def main():
# MODEL_DIR = os.path.join('weights', 'cpm_unet.pkl')
MODEL_DIR = os.path.join('weights', 'cpm_baseline.pkl')
# model = CPM_UNet(num_stages=3, num_joints=17)
model = CPM(num_stages=3, num_joints=17)
model.load_state_dict(torch.load(MODEL_DIR))
demo(model)
if __name__ == "__main__":
main()