当前位置: 首页>>代码示例>>Python>>正文


Python timer.Timer方法代码示例

本文整理汇总了Python中utils.timer.Timer方法的典型用法代码示例。如果您正苦于以下问题:Python timer.Timer方法的具体用法?Python timer.Timer怎么用?Python timer.Timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.timer的用法示例。


在下文中一共展示了timer.Timer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_net_on_dataset

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def test_net_on_dataset(args, multi_gpu=False):
    """Run inference on a dataset."""
    dataset = build_dataset(cfg.TEST.DATASETS, is_train=False)

    total_timer = Timer()
    total_timer.tic()
    if multi_gpu:
        num_images = len(dataset)
        all_boxes, all_segms, all_keyps, all_parss, all_pscores, all_uvs = \
            multi_gpu_test_net_on_dataset(args, num_images)
    else:
        all_boxes, all_segms, all_keyps, all_parss, all_pscores, all_uvs = test_net(args)

    total_timer.toc(average=False)
    logging_rank('Total inference time: {:.3f}s'.format(total_timer.average_time), local_rank=0)

    return evaluation(dataset, all_boxes, all_segms, all_keyps, all_parss, all_pscores, all_uvs) 
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:19,代码来源:test_engine.py

示例2: camera_detector

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def camera_detector(self, cap, wait=10):
        detect_timer = Timer()
        ret, _ = cap.read()

        while ret:
            ret, frame = cap.read()
            detect_timer.tic()
            result = self.detect(frame)
            detect_timer.toc()
            print('Average detecting time: {:.3f}s'.format(
                detect_timer.average_time))

            self.draw_result(frame, result)
            cv2.imshow('Camera', frame)
            cv2.waitKey(wait)

            ret, frame = cap.read() 
开发者ID:hizhangp,项目名称:yolo_tensorflow,代码行数:19,代码来源:test.py

示例3: video_demo

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def video_demo(sess, net, image):
    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes = im_detect(sess, net, image)
    timer.toc()
    print('Detection took {:.3f}s for {:d} object proposals'.format(timer.total_time, boxes.shape[0]))

    # Visualize detections for each class
    CONF_THRESH = 0.85
    NMS_THRESH = 0.3

    inds = np.where(scores[:, 0] > CONF_THRESH)[0]
    scores = scores[inds, 0]
    boxes = boxes[inds, :]
    dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
    keep = nms(dets, NMS_THRESH)
    dets = dets[keep, :]
    return dets
    # vis_detections(image, CLASSES[1], dets, thresh=CONF_THRESH) 
开发者ID:wanjinchang,项目名称:SSH-TensorFlow,代码行数:22,代码来源:demo.py

示例4: demo

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def demo(sess, net, im_file, icdar_dir, oriented=False, ltrb=False):
    """Detect object classes in an image using pre-computed object proposals."""

    # Load the demo image
    im = helper.read_rgb_img(im_file)

    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes, resized_im_shape, im_scale = im_detect(sess, net, im)
    timer.toc()

    # Run TextDetector to merge small box
    line_detector = TextDetector(oriented)

    # text_lines point order: left-top, right-top, left-bottom, right-bottom
    text_lines = line_detector.detect(boxes, scores[:, np.newaxis], resized_im_shape)
    print("Image %s, detect %d text lines in %.3fs" % (im_file, len(text_lines), timer.diff))

    if len(text_lines) != 0:
        text_lines = recover_scale(text_lines, im_scale)

    return save_result_txt(text_lines, icdar_dir, im_file, ltrb) 
开发者ID:Sanster,项目名称:tf_ctpn,代码行数:25,代码来源:icdar.py

示例5: __init__

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def __init__(self, misc_args, log_period=20, tensorboard_logger=None):
        # Output logging period in SGD iterations
        self.misc_args = misc_args
        self.LOG_PERIOD = log_period
        self.tblogger = tensorboard_logger
        self.tb_ignored_keys = ['iter', 'eta']
        self.iter_timer = Timer()
        # Window size for smoothing tracked values (with median filtering)
        self.WIN_SZ = 20
        def create_smoothed_value():
            return SmoothedValue(self.WIN_SZ)
        self.smoothed_losses = defaultdict(create_smoothed_value)
        self.smoothed_metrics = defaultdict(create_smoothed_value)
        self.smoothed_total_loss = SmoothedValue(self.WIN_SZ)
        # For the support of args.iter_size
        self.inner_total_loss = []
        self.inner_losses = defaultdict(list)
        if cfg.FPN.FPN_ON:
            self.inner_loss_rpn_cls = []
            self.inner_loss_rpn_bbox = []
        self.inner_metrics = defaultdict(list) 
开发者ID:roytseng-tw,项目名称:Detectron.pytorch,代码行数:23,代码来源:training_stats.py

示例6: train_model

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def train_model(self, max_iters):
        """Network training loop."""
        last_snapshot_iter = -1
        timer = Timer()
        while self.solver.iter < max_iters:
            # Make one SGD update
            timer.tic()
            
            self.solver.step(1)
            
            timer.toc()
            if self.solver.iter % (10 * self.solver_param.display) == 0:
                print 'speed: {:.3f}s / iter'.format(timer.average_time)

            if self.solver.iter % cfg.TRAIN.SNAPSHOT_ITERS == 0:
                last_snapshot_iter = self.solver.iter
                self.snapshot()

        if last_snapshot_iter != self.solver.iter:
            self.snapshot() 
开发者ID:ppengtang,项目名称:dpl,代码行数:22,代码来源:train.py

示例7: imdb_proposals

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def imdb_proposals(net, imdb):
    """Generate RPN proposals on all images in an imdb."""

    _t = Timer()
    imdb_boxes = [[] for _ in xrange(imdb.num_images)]
    for i in xrange(imdb.num_images):
        im = cv2.imread(imdb.image_path_at(i))
        _t.tic()
        imdb_boxes[i], scores = im_proposals(net, im)
        _t.toc()
        print 'im_proposals: {:d}/{:d} {:.3f}s' \
              .format(i + 1, imdb.num_images, _t.average_time)
        if 0:
            dets = np.hstack((imdb_boxes[i], scores))
            # from IPython import embed; embed()
            _vis_proposals(im, dets[:3, :], thresh=0.9)
            plt.show()

    return imdb_boxes 
开发者ID:playerkk,项目名称:face-py-faster-rcnn,代码行数:21,代码来源:generate.py

示例8: train_model

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def train_model(self, max_iters):
        """Network training loop."""
        last_snapshot_iter = -1
        timer = Timer()
        model_paths = []
        while self.solver.iter < max_iters:
            # Make one SGD update
            timer.tic()
            self.solver.step(1)
            timer.toc()
            if self.solver.iter % (10 * self.solver_param.display) == 0:
                print 'speed: {:.3f}s / iter'.format(timer.average_time)

            if self.solver.iter % cfg.TRAIN.SNAPSHOT_ITERS == 0:
                last_snapshot_iter = self.solver.iter
                model_paths.append(self.snapshot())

        if last_snapshot_iter != self.solver.iter:
            model_paths.append(self.snapshot())
        return model_paths 
开发者ID:playerkk,项目名称:face-py-faster-rcnn,代码行数:22,代码来源:train.py

示例9: _get_feature_scale

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def _get_feature_scale(self, num_images=100):
        TARGET_NORM = 20.0 # Magic value from traditional R-CNN
        _t = Timer()
        roidb = self.imdb.roidb
        total_norm = 0.0
        count = 0.0
        inds = npr.choice(xrange(self.imdb.num_images), size=num_images,
                          replace=False)
        for i_, i in enumerate(inds):
            im = cv2.imread(self.imdb.image_path_at(i))
            if roidb[i]['flipped']:
                im = im[:, ::-1, :]
            _t.tic()
            scores, boxes = im_detect(self.net, im, roidb[i]['boxes'])
            _t.toc()
            feat = self.net.blobs[self.layer].data
            total_norm += np.sqrt((feat ** 2).sum(axis=1)).sum()
            count += feat.shape[0]
            print('{}/{}: avg feature norm: {:.3f}'.format(i_ + 1, num_images,
                                                           total_norm / count))

        return TARGET_NORM * 1.0 / (total_norm / count) 
开发者ID:playerkk,项目名称:face-py-faster-rcnn,代码行数:24,代码来源:train_svms.py

示例10: imdb_proposals_det

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def imdb_proposals_det(net, imdb):
    """Generate RPN proposals on all images in an imdb."""

    _t = Timer()
    imdb_boxes = [[] for _ in xrange(imdb.num_images)]
    for i in xrange(imdb.num_images):
        im = cv2.imread(imdb.image_path_at(i))
        _t.tic()
        boxes, scores = im_proposals(net, im)
        _t.toc()
        print 'im_proposals: {:d}/{:d} {:.3f}s' \
              .format(i + 1, imdb.num_images, _t.average_time)
        dets = np.hstack((boxes, scores))
        imdb_boxes[i] = dets

        if 0:            
            # from IPython import embed; embed()
            _vis_proposals(im, dets[:3, :], thresh=0.9)
            plt.show()

    return imdb_boxes 
开发者ID:chenwuperth,项目名称:rgz_rcnn,代码行数:23,代码来源:generate.py

示例11: demo

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def demo(sess, net, image_name):
  """Detect pedestrians in an image using pre-computed model."""

  # Load the demo image
  im1_file = os.path.join(cfg.DATA_DIR, 'demo', image_name + '_visible.png')
  im1 = cv2.imread(im1_file)
  im2_file = os.path.join(cfg.DATA_DIR, 'demo', image_name + '_lwir.png')
  im2 = cv2.imread(im2_file)
  im = [im1, im2]

  # Detect all object classes and regress object bounds
  timer = Timer()
  timer.tic()
  boxes, scores = im_detect_demo(sess, 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
  CONF_THRESH = 0.5
  NMS_THRESH = 0.3

  dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
  keep = nms(dets, NMS_THRESH)
  dets = dets[keep, :]
  vis_detections(im, dets, thresh=CONF_THRESH) 
开发者ID:Li-Chengyang,项目名称:MSDS-RCNN,代码行数:27,代码来源:demo.py

示例12: add_dup_simhash_caches

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def add_dup_simhash_caches(simhashcache, dup_obj_ids):
    if not dup_obj_ids:
        return
    old_dup_obj_ids = set(dup_obj_ids)
    start_time = time.time()
    for i, dup_obj_id in enumerate(dup_obj_ids, 1):
        with Timer(msg='fuzzy-like:%d %s' % (i, dup_obj_id)):
            logging.info('--' * 100)
            try:
                dup_simhash = SimHashCache.objects.get(obj_id=dup_obj_id)
            except Exception, e:
                print e
                continue
            sim_ratio = fuzz.partial_ratio(s1=simhashcache.text, s2=dup_simhash.text)
            logging.info(simhashcache.text)
            logging.info('--' * 20)
            logging.info(dup_simhash.text)
            logging.info("%d %s %s" % (sim_ratio, simhashcache.obj_id, dup_simhash.obj_id))

            if dup_simhash not in old_dup_obj_ids:
                if sim_ratio > 50:
                    old_dup_obj_ids.add(dup_obj_id)
            else:
                if sim_ratio <= 50:
                    old_dup_obj_ids.remove(dup_obj_id) 
开发者ID:likaiguo,项目名称:simhashpy,代码行数:27,代码来源:__init__.py

示例13: add_and_find_dup

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def add_and_find_dup(self, obj_id, value, k=16):
        """
        添加一个键值对文档,并且找到最相似的文档并且写入 simhashcache中,
        目的: 为了在建立的过程中尽量找到相关连的simhash.

        实际上在一个大规模的文档排重的过程中,后边总会有一部分的文档与前边相似
        为了避免再次重复读入,所以构建该子段
        """
        simhash = BeautifulSoup(value, "lxml").get_text('\n')
        simhashcache = self.add(obj_id=obj_id, simhash=simhash)
        with Timer(msg='find'):
            dup_obj_ids = self.find(value=simhash, k=k, exclude_obj_id_contain=obj_id.split('_')[0])
        if dup_obj_ids:
            with Timer(msg='add_dup_simhash_caches'):
                add_dup_simhash_caches(simhashcache, dup_obj_ids)

        return simhashcache 
开发者ID:likaiguo,项目名称:simhashpy,代码行数:19,代码来源:__init__.py

示例14: __init__

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def __init__(self, misc_args, log_period=20, tensorboard_logger=None):
        # Output logging period in SGD iterations
        self.misc_args = misc_args
        self.LOG_PERIOD = log_period
        self.tblogger = tensorboard_logger
        self.tb_ignored_keys = ['iter', 'eta']
        self.iter_timer = Timer()
        # Window size for smoothing tracked values (with median filtering)
        self.WIN_SZ = 20
        def create_smoothed_value():
            return SmoothedValue(self.WIN_SZ)
        self.smoothed_losses = defaultdict(create_smoothed_value)
        self.smoothed_total_loss = SmoothedValue(self.WIN_SZ)
        # For the support of args.iter_size
        self.inner_total_loss = []
        self.inner_losses = defaultdict(list) 
开发者ID:ppengtang,项目名称:pcl.pytorch,代码行数:18,代码来源:training_stats.py

示例15: camera_detector

# 需要导入模块: from utils import timer [as 别名]
# 或者: from utils.timer import Timer [as 别名]
def camera_detector(self, cap, wait=10):     #相机检测
        detect_timer = Timer()
        ret, _ = cap.read()

        while ret:
            ret, frame = cap.read()
            detect_timer.tic()
            result = self.detect(frame)
            detect_timer.toc()
            print('Average detecting time: {:.3f}s'.format(
                detect_timer.average_time))

            self.draw_result(frame, result)
            cv2.imshow('Camera', frame)
            cv2.waitKey(wait)

            ret, frame = cap.read() 
开发者ID:TowardsNorth,项目名称:yolo_v1_tensorflow_guiyu,代码行数:19,代码来源:test.py


注:本文中的utils.timer.Timer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。