Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROFILE: change averaging to improve performance in PAF calculation and added profiling info. #3

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/evaluation/eval_net.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import scipy.stats

import time

import cv2
Expand All @@ -19,8 +21,11 @@ def eval_net(data_loader, model, opts):
outputs = []
dataset_len = 100 #len(dataset)
keypoints_list = []
runtimes = []
with torch.no_grad():
for i in range(dataset_len):
print(i)
start = time.time()
imgs, heatmap_t, paf_t, ignore_mask_t, keypoints = dataset.get_imgs_multiscale(i, scales,flip=False)
n_imgs = len(imgs)
assert(n_imgs == n_scales)
Expand All @@ -33,25 +38,35 @@ def eval_net(data_loader, model, opts):
h, w = img.shape[1], img.shape[2]
imgs_np[j,:,:h,:w] = img
img_basic = imgs[0]
heatmap_avg = np.zeros(heatmap_t.shape)
paf_avg = np.zeros(paf_t.shape)

heatmap_avg_lst = []
paf_avg_lst = []
print("first loop", time.time() - start)
for j in range(0, n_imgs):
imgs_torch = torch.from_numpy(imgs_np[j:j+1]).float().cuda()
heatmaps, pafs = model(imgs_torch)
heatmap = heatmaps[-1].data.cpu().numpy()[0, :, :heights[j]//8, :widths[j]//8]
paf = pafs[-1].data.cpu().numpy()[0, :, :heights[j]//8, :widths[j]//8]
heatmap = resize_hm(heatmap, (widths[0], heights[0]))
paf = resize_hm(paf, (widths[0], heights[0]))
heatmap_avg += heatmap/n_imgs
paf_avg += paf/n_imgs
heatmap_avg_lst += [heatmap]
paf_avg_lst += [paf]
heatmap_avg = sum(heatmap_avg_lst)/n_imgs
paf_avg = sum(paf_avg_lst)/n_imgs
print("second loop", time.time() - start)
#visualize_output_single(img_basic, heatmap_t, paf_t, ignore_mask_t, heatmap_avg, paf_avg)
img_basic = denormalize(img_basic)
param = {'thre1': 0.1, 'thre2': 0.05, 'thre3': 0.5}
canvas, to_plot, candidate, subset = decode_pose(img_basic, param, heatmap_avg, paf_avg)
final = time.time()-start
runtimes += [final]
print("both loops took ", final)
keypoints_list.append(keypoints)
append_result(dataset.indices[i], subset, candidate, outputs)
vis_path = os.path.join(opts.saveDir, 'viz')
if not os.path.exists(vis_path):
os.makedirs(vis_path)
cv2.imwrite(vis_path+'/{}.png'.format(i), to_plot)
print ("runtime statistics for all images")
print(scipy.stats.describe(runtimes))
return outputs, dataset.indices[:dataset_len]