本文整理汇总了Python中util.Timer方法的典型用法代码示例。如果您正苦于以下问题:Python util.Timer方法的具体用法?Python util.Timer怎么用?Python util.Timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util
的用法示例。
在下文中一共展示了util.Timer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detect_image
# 需要导入模块: import util [as 别名]
# 或者: from util import Timer [as 别名]
def detect_image(detector, device, args):
"""Demo for detecting images."""
timer = Timer()
while True:
image_file = input('Enter image file path: ')
image = cv.imread(image_file)
timer.tic()
pred_points = detect_marking_points(
detector, image, args.thresh, device)
slots = None
if pred_points and args.inference_slot:
marking_points = list(list(zip(*pred_points))[1])
slots = inference_slots(marking_points)
timer.toc()
plot_points(image, pred_points)
plot_slots(image, pred_points, slots)
cv.imshow('demo', image)
cv.waitKey(1)
if args.save:
cv.imwrite('save.jpg', image, [int(cv.IMWRITE_JPEG_QUALITY), 100])
示例2: detect_video
# 需要导入模块: import util [as 别名]
# 或者: from util import Timer [as 别名]
def detect_video(detector, device, args):
"""Demo for detecting video."""
timer = Timer()
input_video = cv.VideoCapture(args.video)
frame_width = int(input_video.get(cv.CAP_PROP_FRAME_WIDTH))
frame_height = int(input_video.get(cv.CAP_PROP_FRAME_HEIGHT))
output_video = cv.VideoWriter()
if args.save:
output_video.open('record.avi', cv.VideoWriter_fourcc(*'XVID'),
input_video.get(cv.CAP_PROP_FPS),
(frame_width, frame_height), True)
frame = np.empty([frame_height, frame_width, 3], dtype=np.uint8)
while input_video.read(frame)[0]:
timer.tic()
pred_points = detect_marking_points(
detector, frame, args.thresh, device)
slots = None
if pred_points and args.inference_slot:
marking_points = list(list(zip(*pred_points))[1])
slots = inference_slots(marking_points)
timer.toc()
plot_points(frame, pred_points)
plot_slots(frame, pred_points, slots)
cv.imshow('demo', frame)
cv.waitKey(1)
if args.save:
output_video.write(frame)
print("Average time: ", timer.calc_average_time(), "s.")
input_video.release()
output_video.release()
示例3: temporal_join
# 需要导入模块: import util [as 别名]
# 或者: from util import Timer [as 别名]
def temporal_join(u, v, v_name, key, time_col):
timer = Timer()
if isinstance(key, list):
assert len(key) == 1
key = key[0]
tmp_u = u[[time_col, key]]
timer.check("select")
tmp_u = pd.concat([tmp_u, v], keys=['u', 'v'], sort=False)
timer.check("concat")
rehash_key = f'rehash_{key}'
tmp_u[rehash_key] = tmp_u[key].apply(lambda x: hash(x) % CONSTANT.HASH_MAX)
timer.check("rehash_key")
tmp_u.sort_values(time_col, inplace=True)
timer.check("sort")
agg_funcs = {col: Config.aggregate_op(col) for col in v if col != key
and not col.startswith(CONSTANT.TIME_PREFIX)
and not col.startswith(CONSTANT.MULTI_CAT_PREFIX)}
tmp_u = tmp_u.groupby(rehash_key).rolling(5).agg(agg_funcs)
timer.check("group & rolling & agg")
tmp_u.reset_index(0, drop=True, inplace=True) # drop rehash index
timer.check("reset_index")
tmp_u.columns = tmp_u.columns.map(lambda a:
f"{CONSTANT.NUMERICAL_PREFIX}{a[1].upper()}_ROLLING5({v_name}.{a[0]})")
if tmp_u.empty:
log("empty tmp_u, return u")
return u
ret = pd.concat([u, tmp_u.loc['u']], axis=1, sort=False)
timer.check("final concat")
del tmp_u
return ret