本文整理汇总了Python中utils.timer.Timer.total_time方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.total_time方法的具体用法?Python Timer.total_time怎么用?Python Timer.total_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.timer.Timer
的用法示例。
在下文中一共展示了Timer.total_time方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: demo
# 需要导入模块: from utils.timer import Timer [as 别名]
# 或者: from utils.timer.Timer import total_time [as 别名]
def demo(net, image_name):
"""Detect object classes in an image using pre-computed object proposals."""
# Load the demo image
im_file = os.path.join(cfg.DATA_DIR, 'demo', image_name)
im = cv2.imread(im_file)
# Detect all object classes and regress object bounds
timer = Timer()
timer.tic()
scores, boxes = im_detect(net, im)
timer.toc()
print('Detection took {:.3f}s for {:d} object proposals'.format(timer.total_time(), boxes.shape[0]))
# Visualize detections for each class
thresh = 0.8 # CONF_THRESH
NMS_THRESH = 0.3
im = im[:, :, (2, 1, 0)]
fig, ax = plt.subplots(figsize=(12, 12))
ax.imshow(im, aspect='equal')
cntr = -1
for cls_ind, cls in enumerate(CLASSES[1:]):
cls_ind += 1 # because we skipped background
cls_boxes = boxes[:, 4*cls_ind:4*(cls_ind + 1)]
cls_scores = scores[:, cls_ind]
dets = np.hstack((cls_boxes,
cls_scores[:, np.newaxis])).astype(np.float32)
keep = nms(torch.from_numpy(dets), NMS_THRESH)
dets = dets[keep.numpy(), :]
inds = np.where(dets[:, -1] >= thresh)[0]
if len(inds) == 0:
continue
else:
cntr += 1
for i in inds:
bbox = dets[i, :4]
score = dets[i, -1]
ax.add_patch(
plt.Rectangle((bbox[0], bbox[1]),
bbox[2] - bbox[0],
bbox[3] - bbox[1], fill=False,
edgecolor=COLORS[cntr % len(COLORS)], linewidth=3.5)
)
ax.text(bbox[0], bbox[1] - 2,
'{:s} {:.3f}'.format(cls, score),
bbox=dict(facecolor='blue', alpha=0.5),
fontsize=14, color='white')
ax.set_title('All detections with threshold >= {:.1f}'.format(thresh), fontsize=14)
plt.axis('off')
plt.tight_layout()
plt.savefig('demo_' + image_name)
print('Saved to `{}`'.format(os.path.join(os.getcwd(), 'demo_' + image_name)))