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


Python config.get_output_dir方法代码示例

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


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

示例1: test_net

# 需要导入模块: from model import config [as 别名]
# 或者: from model.config import get_output_dir [as 别名]
def test_net(sess, net, imdb, weights_filename, thresh=0.05):
    np.random.seed(cfg.RNG_SEED)
    """Test a SSH network on an image database."""
    num_images = len(imdb.image_index)
    # all detections are collected into:
    #  all_boxes[cls][image] = N x 5 array of detections in
    #  (x1, y1, x2, y2, score)
    all_boxes = [[] for _ in range(num_images)]

    output_dir = get_output_dir(imdb, weights_filename)
    # timers
    _t = {'im_detect': Timer(), 'misc': Timer()}

    for i in range(num_images):
        im = cv2.imread(imdb.image_path_at(i))

        _t['im_detect'].tic()
        scores, boxes = im_detect(sess, net, im)
        _t['im_detect'].toc()

        _t['misc'].tic()

        inds = np.where(scores[:, 0] > thresh)[0]
        scores = scores[inds, 0]
        boxes = boxes[inds, :]
        dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
        keep = nms(dets, cfg.TEST.NMS)
        dets = dets[keep, :]
        all_boxes[i] = det
        _t['misc'].toc()

        print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
              .format(i + 1, num_images, _t['im_detect'].average_time,
                      _t['misc'].average_time))

    det_file = os.path.join(output_dir, 'detections.pkl')
    with open(det_file, 'wb') as f:
        pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)

    print('Evaluating detections')
    imdb.evaluate_detections(all_boxes, output_dir) 
开发者ID:wanjinchang,项目名称:SSH-TensorFlow,代码行数:43,代码来源:test.py

示例2: test_net_base

# 需要导入模块: from model import config [as 别名]
# 或者: from model.config import get_output_dir [as 别名]
def test_net_base(sess, net, imdb, roidb, weights_filename, visualize=False):
  np.random.seed(cfg.RNG_SEED)
  """Test a Fast R-CNN network on an image database."""
  num_images = len(roidb)
  output_dir = get_output_dir(imdb, weights_filename)
  output_dir_image = os.path.join(output_dir, 'images')
  if visualize and not os.path.exists(output_dir_image):
    os.makedirs(output_dir_image)
  all_scores = [[] for _ in range(num_images)]

  # timers
  _t = {'score' : Timer()}

  for i in range(num_images):
    _t['score'].tic()
    all_scores[i], blobs = im_detect(sess, imdb, net, [roidb[i]])
    _t['score'].toc()

    print('score: {:d}/{:d} {:.3f}s' \
        .format(i + 1, num_images, _t['score'].average_time))

    if visualize and i % 10 == 0:
      basename = os.path.basename(imdb.image_path_at(i)).split('.')[0]
      im_vis, wrong = draw_predicted_boxes_test(blobs['data'], all_scores[i], blobs['gt_boxes'])
      if wrong:
        out_image = os.path.join(output_dir_image, basename + '.jpg')
        print(out_image)
        cv2.imwrite(out_image, im_vis)

  res_file = os.path.join(output_dir, 'results.pkl')
  with open(res_file, 'wb') as f:
    pickle.dump(all_scores, f, pickle.HIGHEST_PROTOCOL)

  print('Evaluating detections')
  mcls_sc, mcls_ac, mcls_ap, mins_sc, mins_ac, mins_ap = imdb.evaluate(all_scores, output_dir)
  eval_file = os.path.join(output_dir, 'results.txt')
  with open(eval_file, 'w') as f:
    f.write('{:.3f} {:.3f} {:.3f} {:.3f}'.format(mins_ap, mins_ac, mcls_ap, mcls_ac)) 
开发者ID:endernewton,项目名称:iter-reason,代码行数:40,代码来源:test.py

示例3: test_net_memory

# 需要导入模块: from model import config [as 别名]
# 或者: from model.config import get_output_dir [as 别名]
def test_net_memory(sess, net, imdb, roidb, weights_filename, visualize=False, iter=0):
  np.random.seed(cfg.RNG_SEED)
  """Test a Fast R-CNN network on an image database."""
  num_images = len(roidb)
  output_dir = get_output_dir(imdb, weights_filename + "_iter%02d" % iter)
  output_dir_image = os.path.join(output_dir, 'images')
  if visualize and not os.path.exists(output_dir_image):
    os.makedirs(output_dir_image)
  all_scores = [[] for _ in range(num_images)]

  # timers
  _t = {'score' : Timer()}

  for i in range(num_images):
    _t['score'].tic()
    all_scores[i], blobs = im_detect_iter(sess, imdb, net, [roidb[i]], iter)
    _t['score'].toc()

    print('score: {:d}/{:d} {:.3f}s' \
        .format(i + 1, num_images, _t['score'].average_time))

    if visualize and i % 10 == 0:
      basename = os.path.basename(imdb.image_path_at(i)).split('.')[0]
      im_vis, wrong = draw_predicted_boxes_test(blobs['data'], all_scores[i], blobs['gt_boxes'])
      if wrong:
        out_image = os.path.join(output_dir_image, basename + '.jpg')
        print(out_image)
        cv2.imwrite(out_image, im_vis)

  res_file = os.path.join(output_dir, 'results.pkl')
  with open(res_file, 'wb') as f:
    pickle.dump(all_scores, f, pickle.HIGHEST_PROTOCOL)

  print('Evaluating detections')
  mcls_sc, mcls_ac, mcls_ap, mins_sc, mins_ac, mins_ap = imdb.evaluate(all_scores, output_dir)
  eval_file = os.path.join(output_dir, 'results.txt')
  with open(eval_file, 'w') as f:
    f.write('{:.3f} {:.3f} {:.3f} {:.3f}'.format(mins_ap, mins_ac, mcls_ap, mcls_ac)) 
开发者ID:endernewton,项目名称:iter-reason,代码行数:40,代码来源:test.py

示例4: test_net

# 需要导入模块: from model import config [as 别名]
# 或者: from model.config import get_output_dir [as 别名]
def test_net(net, imdb, weights_filename, max_per_image=100, thresh=0.):
  np.random.seed(cfg.RNG_SEED)
  """Test a Fast R-CNN network on an image database."""
  num_images = len(imdb.image_index)
  # all detections are collected into:
  #  all_boxes[cls][image] = N x 5 array of detections in
  #  (x1, y1, x2, y2, score)
  all_boxes = [[[] for _ in range(num_images)]
         for _ in range(imdb.num_classes)]

  output_dir = get_output_dir(imdb, weights_filename)
  # timers
  _t = {'im_detect' : Timer(), 'misc' : Timer()}

  for i in range(num_images):
    im = cv2.imread(imdb.image_path_at(i))

    _t['im_detect'].tic()
    scores, boxes = im_detect(net, im)
    _t['im_detect'].toc()

    _t['misc'].tic()

    # skip j = 0, because it's the background class
    for j in range(1, imdb.num_classes):
      inds = np.where(scores[:, j] > thresh)[0]
      cls_scores = scores[inds, j]
      cls_boxes = boxes[inds, j*4:(j+1)*4]
      cls_dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])) \
        .astype(np.float32, copy=False)
      keep = nms(torch.from_numpy(cls_dets), cfg.TEST.NMS).numpy() if cls_dets.size > 0 else []
      cls_dets = cls_dets[keep, :]
      all_boxes[j][i] = cls_dets

    # Limit to max_per_image detections *over all classes*
    if max_per_image > 0:
      image_scores = np.hstack([all_boxes[j][i][:, -1]
                    for j in range(1, imdb.num_classes)])
      if len(image_scores) > max_per_image:
        image_thresh = np.sort(image_scores)[-max_per_image]
        for j in range(1, imdb.num_classes):
          keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0]
          all_boxes[j][i] = all_boxes[j][i][keep, :]
    _t['misc'].toc()

    print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
        .format(i + 1, num_images, _t['im_detect'].average_time(),
            _t['misc'].average_time()))

  det_file = os.path.join(output_dir, 'detections.pkl')
  with open(det_file, 'wb') as f:
    pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)

  print('Evaluating detections')
  imdb.evaluate_detections(all_boxes, output_dir) 
开发者ID:yxgeee,项目名称:pytorch-FPN,代码行数:57,代码来源:test.py

示例5: test_net

# 需要导入模块: from model import config [as 别名]
# 或者: from model.config import get_output_dir [as 别名]
def test_net(sess, net, imdb, weights_filename, max_per_image=100, thresh=0.0):
  np.random.seed(cfg.RNG_SEED)
  """Test a Fast R-CNN network on an image database."""
  num_images = len(imdb.image_index)
  # all detections are collected into:
  #  all_boxes[cls][image] = N x 5 array of detections in
  #  (x1, y1, x2, y2, score)
  all_boxes = [[[] for _ in range(num_images)]
         for _ in range(imdb.num_classes)]

  output_dir = get_output_dir(imdb, weights_filename)
  if os.path.isfile(os.path.join(output_dir, 'detections.pkl')):
    all_boxes=pickle.load(open(os.path.join(output_dir, 'detections.pkl'),'r'))
  else:  
    # timers
    _t = {'im_detect' : Timer(), 'misc' : Timer()}

    for i in range(num_images):
      im = cv2.imread(imdb.image_path_at(i))

      _t['im_detect'].tic()
      scores, boxes,_ ,_ = im_detect(sess, net, im)
      _t['im_detect'].toc()

      _t['misc'].tic()

      # skip j = 0, because it's the background class
      for j in range(1, imdb.num_classes):
        inds = np.where(scores[:, j] > thresh)[0]
        cls_scores = scores[inds, j]
        cls_boxes = boxes[inds, j*4:(j+1)*4]
        cls_dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])) \
          .astype(np.float32, copy=False)
        keep = nms(cls_dets, cfg.TEST.NMS)
        cls_dets = cls_dets[keep, :]
        all_boxes[j][i] = cls_dets

      # Limit to max_per_image detections *over all classes*
      if max_per_image > 0:
        image_scores = np.hstack([all_boxes[j][i][:, -1]
                      for j in range(1, imdb.num_classes)])
        if len(image_scores) > max_per_image:
          image_thresh = np.sort(image_scores)[-max_per_image]
          for j in range(1, imdb.num_classes):
            keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0]
            all_boxes[j][i] = all_boxes[j][i][keep, :]
      _t['misc'].toc()

      print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
          .format(i + 1, num_images, _t['im_detect'].average_time,
              _t['misc'].average_time))

    det_file = os.path.join(output_dir, 'detections_{:f}.pkl'.format(10))
    with open(det_file, 'wb') as f:
      pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)

  print('Evaluating detections')
  imdb.evaluate_detections(all_boxes, output_dir) 
开发者ID:pengzhou1108,项目名称:RGB-N,代码行数:60,代码来源:test.py

示例6: test_net

# 需要导入模块: from model import config [as 别名]
# 或者: from model.config import get_output_dir [as 别名]
def test_net(sess, net, imdb, weights_filename, max_per_image=100, thresh=0.):
  np.random.seed(cfg.RNG_SEED)
  """Test a Fast R-CNN network on an image database."""
  num_images = len(imdb.image_index)
  # all detections are collected into:
  #  all_boxes[cls][image] = N x 5 array of detections in
  #  (x1, y1, x2, y2, score)
  all_boxes = [[[] for _ in range(num_images)]
         for _ in range(imdb.num_classes)]

  output_dir = get_output_dir(imdb, weights_filename)
  # timers
  _t = {'im_detect' : Timer(), 'misc' : Timer()}

  for i in range(num_images):
    im = cv2.imread(imdb.image_path_at(i))

    _t['im_detect'].tic()
    scores, boxes = im_detect(sess, net, im)
    _t['im_detect'].toc()

    _t['misc'].tic()

    # skip j = 0, because it's the background class
    for j in range(1, imdb.num_classes):
      inds = np.where(scores[:, j] > thresh)[0]
      cls_scores = scores[inds, j]
      cls_boxes = boxes[inds, j*4:(j+1)*4]
      cls_dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])) \
        .astype(np.float32, copy=False)
      keep = nms(cls_dets, cfg.TEST.NMS)
      cls_dets = cls_dets[keep, :]
      all_boxes[j][i] = cls_dets

    # Limit to max_per_image detections *over all classes*
    if max_per_image > 0:
      image_scores = np.hstack([all_boxes[j][i][:, -1]
                    for j in range(1, imdb.num_classes)])
      if len(image_scores) > max_per_image:
        image_thresh = np.sort(image_scores)[-max_per_image]
        for j in range(1, imdb.num_classes):
          keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0]
          all_boxes[j][i] = all_boxes[j][i][keep, :]
    _t['misc'].toc()

    print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
        .format(i + 1, num_images, _t['im_detect'].average_time,
            _t['misc'].average_time))

  det_file = os.path.join(output_dir, 'detections.pkl')
  with open(det_file, 'wb') as f:
    pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)

  print('Evaluating detections')
  imdb.evaluate_detections(all_boxes, output_dir) 
开发者ID:endernewton,项目名称:tf-faster-rcnn,代码行数:57,代码来源:test.py


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