當前位置: 首頁>>代碼示例>>Python>>正文


Python config.get_output_dir方法代碼示例

本文整理匯總了Python中fast_rcnn.config.get_output_dir方法的典型用法代碼示例。如果您正苦於以下問題:Python config.get_output_dir方法的具體用法?Python config.get_output_dir怎麽用?Python config.get_output_dir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fast_rcnn.config的用法示例。


在下文中一共展示了config.get_output_dir方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_rpn_msr_net

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def test_rpn_msr_net(net, imdb):

    output_dir = get_output_dir(imdb, net)
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    det_file = os.path.join(output_dir, 'detections.pkl')
    if os.path.exists(det_file):
        with open(det_file, 'rb') as fid:
            all_boxes = cPickle.load(fid)
        print 'Detections loaded from {}'.format(det_file)

        print 'Evaluating detections'
        imdb.evaluate_proposals_msr(all_boxes, output_dir)
        return

    # Generate proposals on the imdb
    all_boxes = imdb_proposals_det(net, imdb)

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

    print 'Evaluating detections'
    imdb.evaluate_proposals_msr(all_boxes, output_dir) 
開發者ID:tanshen,項目名稱:SubCNN,代碼行數:27,代碼來源:test.py

示例2: test_net_VOC

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def test_net_VOC(net, imdb):
    """Test a Fast R-CNN network on an image database."""
    num_images = len(imdb.image_index)
    # heuristic: keep an average of 40 detections per class per images prior
    # to NMS

    output_dir = get_output_dir(imdb, net)
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    # timers
    _t = {'im_cls' : Timer(), 'misc' : Timer()}

    roidb = imdb.roidb
    for i in xrange(num_images):
        im = cv2.imread(imdb.image_path_at(i))
        _t['im_cls'].tic()
        scores = im_cls(net, im, roidb[i]['boxes'])
        # scores = np.max(scores, axis=0)
        scores = np.mean(scores, axis=0)
        _t['im_cls'].toc()

        _t['misc'].tic()
        for j in xrange(imdb.num_classes):
            cls_file = os.path.join(output_dir, 'comp2_cls_test_'+imdb.classes[j]+'.txt')
            with open(cls_file, 'a') as f:
                f.write(imdb.image_index[i]+' '+str(scores[j])+'\n')
            
        _t['misc'].toc()

        print 'im_cls: {:d}/{:d} {:.3f}s {:.3f}s' \
              .format(i + 1, num_images, _t['im_cls'].average_time,
                      _t['misc'].average_time) 
開發者ID:ppengtang,項目名稱:dpl,代碼行數:35,代碼來源:test.py

示例3: train_rpn

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def train_rpn(queue=None, imdb_name=None, init_model=None, solver=None,
              max_iters=None, cfg=None):
    """Train a Region Proposal Network in a separate training process.
    """

    # Not using any proposals, just ground-truth boxes
    cfg.TRAIN.HAS_RPN = True
    cfg.TRAIN.BBOX_REG = False  # applies only to Fast R-CNN bbox regression
    cfg.TRAIN.PROPOSAL_METHOD = 'gt'
    cfg.TRAIN.IMS_PER_BATCH = 1
    print 'Init model: {}'.format(init_model)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    roidb, imdb = get_roidb(imdb_name)
    print 'roidb len: {}'.format(len(roidb))
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)

    model_paths = train_net(solver, roidb, output_dir,
                            pretrained_model=init_model,
                            max_iters=max_iters)
    # Cleanup all but the final model
    for i in model_paths[:-1]:
        os.remove(i)
    rpn_model_path = model_paths[-1]
    # Send final model path through the multiprocessing queue
    queue.put({'model_path': rpn_model_path}) 
開發者ID:playerkk,項目名稱:face-py-faster-rcnn,代碼行數:33,代碼來源:train_faster_rcnn_alt_opt.py

示例4: rpn_generate

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def rpn_generate(queue=None, imdb_name=None, rpn_model_path=None, cfg=None,
                 rpn_test_prototxt=None):
    """Use a trained RPN to generate proposals.
    """

    cfg.TEST.RPN_PRE_NMS_TOP_N = -1     # no pre NMS filtering
    cfg.TEST.RPN_POST_NMS_TOP_N = 2000  # limit top boxes after NMS
    print 'RPN model: {}'.format(rpn_model_path)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    # NOTE: the matlab implementation computes proposals on flipped images, too.
    # We compute them on the image once and then flip the already computed
    # proposals. This might cause a minor loss in mAP (less proposal jittering).
    imdb = get_imdb(imdb_name)
    print 'Loaded dataset `{:s}` for proposal generation'.format(imdb.name)

    # Load RPN and configure output directory
    rpn_net = caffe.Net(rpn_test_prototxt, rpn_model_path, caffe.TEST)
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    # Generate proposals on the imdb
    rpn_proposals = imdb_proposals(rpn_net, imdb)
    # Write proposals to disk and send the proposal file path through the
    # multiprocessing queue
    rpn_net_name = os.path.splitext(os.path.basename(rpn_model_path))[0]
    rpn_proposals_path = os.path.join(
        output_dir, rpn_net_name + '_proposals.pkl')
    with open(rpn_proposals_path, 'wb') as f:
        cPickle.dump(rpn_proposals, f, cPickle.HIGHEST_PROTOCOL)
    print 'Wrote RPN proposals to {}'.format(rpn_proposals_path)
    queue.put({'proposal_path': rpn_proposals_path}) 
開發者ID:playerkk,項目名稱:face-py-faster-rcnn,代碼行數:37,代碼來源:train_faster_rcnn_alt_opt.py

示例5: train_fast_rcnn

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def train_fast_rcnn(queue=None, imdb_name=None, init_model=None, solver=None,
                    max_iters=None, cfg=None, rpn_file=None):
    """Train a Fast R-CNN using proposals generated by an RPN.
    """

    cfg.TRAIN.HAS_RPN = False           # not generating prosals on-the-fly
    cfg.TRAIN.PROPOSAL_METHOD = 'rpn'   # use pre-computed RPN proposals instead
    cfg.TRAIN.IMS_PER_BATCH = 2
    print 'Init model: {}'.format(init_model)
    print 'RPN proposals: {}'.format(rpn_file)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    roidb, imdb = get_roidb(imdb_name, rpn_file=rpn_file)
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    # Train Fast R-CNN
    model_paths = train_net(solver, roidb, output_dir,
                            pretrained_model=init_model,
                            max_iters=max_iters)
    # Cleanup all but the final model
    for i in model_paths[:-1]:
        os.remove(i)
    fast_rcnn_model_path = model_paths[-1]
    # Send Fast R-CNN model path over the multiprocessing queue
    queue.put({'model_path': fast_rcnn_model_path}) 
開發者ID:playerkk,項目名稱:face-py-faster-rcnn,代碼行數:31,代碼來源:train_faster_rcnn_alt_opt.py

示例6: train_rpn

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def train_rpn(queue=None, imdb_name=None, init_model=None, solver=None,
              max_iters=None, cfg=None, output_cache=None):
    """Train a Region Proposal Network in a separate training process.
    """

    # Not using any proposals, just ground-truth boxes
    cfg.TRAIN.HAS_RPN = True
    cfg.TRAIN.BBOX_REG = False  # applies only to R-FCN bbox regression
    cfg.TRAIN.PROPOSAL_METHOD = 'gt'
    cfg.TRAIN.IMS_PER_BATCH = 1
    print 'Init model: {}'.format(init_model)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    roidb, imdb = get_roidb(imdb_name)
    print 'roidb len: {}'.format(len(roidb))
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    final_caffemodel = os.path.join(output_dir, output_cache)

    if os.path.exists(final_caffemodel):
        queue.put({'model_path': final_caffemodel})
    else:
        model_paths = train_net(solver, roidb, output_dir,
                                pretrained_model=init_model,
                                max_iters=max_iters)
        # Cleanup all but the final model
        for i in model_paths[:-1]:
            os.remove(i)
        rpn_model_path = model_paths[-1]
        # Send final model path through the multiprocessing queue
        shutil.copyfile(rpn_model_path, final_caffemodel)
        queue.put({'model_path': final_caffemodel}) 
開發者ID:ucloud,項目名稱:uai-sdk,代碼行數:38,代碼來源:train_rfcn_alt_opt_5stage.py

示例7: rpn_generate

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def rpn_generate(queue=None, imdb_name=None, rpn_model_path=None, cfg=None,
                 rpn_test_prototxt=None):
    """Use a trained RPN to generate proposals.
    """

    cfg.TEST.RPN_PRE_NMS_TOP_N = 6000     # no pre NMS filtering
    cfg.TEST.RPN_POST_NMS_TOP_N = 300  # limit top boxes after NMS
    print 'RPN model: {}'.format(rpn_model_path)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    # NOTE: the matlab implementation computes proposals on flipped images, too.
    # We compute them on the image once and then flip the already computed
    # proposals. This might cause a minor loss in mAP (less proposal jittering).
    imdb = get_imdb(imdb_name)
    print 'Loaded dataset `{:s}` for proposal generation'.format(imdb.name)

    # Load RPN and configure output directory
    rpn_net = caffe.Net(rpn_test_prototxt, rpn_model_path, caffe.TEST)
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    rpn_net_name = os.path.splitext(os.path.basename(rpn_model_path))[0]
    rpn_proposals_path = os.path.join(
        output_dir, rpn_net_name + '_proposals.pkl')

    # Generate proposals on the imdb

    # Write proposals to disk and send the proposal file path through the
    # multiprocessing queue
    if not os.path.exists(rpn_proposals_path):
        rpn_proposals = imdb_proposals(rpn_net, imdb)
        with open(rpn_proposals_path, 'wb') as f:
            cPickle.dump(rpn_proposals, f, cPickle.HIGHEST_PROTOCOL)
    queue.put({'proposal_path': rpn_proposals_path})
    print 'Wrote RPN proposals to {}'.format(rpn_proposals_path) 
開發者ID:ucloud,項目名稱:uai-sdk,代碼行數:40,代碼來源:train_rfcn_alt_opt_5stage.py

示例8: train_rfcn

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def train_rfcn(queue=None, imdb_name=None, init_model=None, solver=None,
                    max_iters=None, cfg=None, rpn_file=None, output_cache=None):
    """Train a R-FCN using proposals generated by an RPN.
    """

    cfg.TRAIN.HAS_RPN = False           # not generating prosals on-the-fly
    cfg.TRAIN.PROPOSAL_METHOD = 'rpn'   # use pre-computed RPN proposals instead
    cfg.TRAIN.IMS_PER_BATCH = 1
    print 'Init model: {}'.format(init_model)
    print 'RPN proposals: {}'.format(rpn_file)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    roidb, imdb = get_roidb(imdb_name, rpn_file=rpn_file)
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    # Train R-FCN
    # Send R-FCN model path over the multiprocessing queue
    final_caffemodel = os.path.join(output_dir, output_cache)

    if os.path.exists(final_caffemodel):
        queue.put({'model_path': final_caffemodel})
    else:
        model_paths = train_net(solver, roidb, output_dir,
                                pretrained_model=init_model,
                                max_iters=max_iters)
        # Cleanup all but the final model
        for i in model_paths[:-1]:
            os.remove(i)
        rfcn_model_path = model_paths[-1]
        # Send final model path through the multiprocessing queue
        shutil.copyfile(rfcn_model_path, final_caffemodel)
        queue.put({'model_path': final_caffemodel}) 
開發者ID:YuwenXiong,項目名稱:py-R-FCN,代碼行數:38,代碼來源:train_rfcn_alt_opt_5stage.py

示例9: train_rpn

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def train_rpn(queue=None, imdb_name=None, init_model=None, solver=None,
              max_iters=None, cfg=None, output_dir=None):
    """Train a Region Proposal Network in a separate training process.
    """

    # Not using any proposals, just ground-truth boxes
    cfg.TRAIN.HAS_RPN = True
    cfg.TRAIN.BBOX_REG = False  # applies only to Fast R-CNN bbox regression
    cfg.TRAIN.PROPOSAL_METHOD = 'gt'
    cfg.TRAIN.IMS_PER_BATCH = 1
    print 'Init model: {}'.format(init_model)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    roidb, imdb = get_roidb(imdb_name)
    # print 'first image: ',imdb.gt_roidb()
    # print 'roidb len: {}'.format(len(roidb))
    if output_dir==None:
        output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    print 'len roidb=',len(roidb)
    model_paths = train_net(solver, roidb, output_dir,
                            pretrained_model=init_model,
                            max_iters=max_iters)
    # Cleanup all but the final model
    for i in model_paths[:-1]:
        os.remove(i)
    rpn_model_path = model_paths[-1]
    # Send final model path through the multiprocessing queue
    queue.put({'model_path': rpn_model_path}) 
開發者ID:djdam,項目名稱:faster-rcnn-scenarios,代碼行數:35,代碼來源:train.py

示例10: rpn_generate

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def rpn_generate(queue=None, imdb_name=None, rpn_model_path=None, cfg=None,
                 rpn_test_prototxt=None, output_dir=None, part_id=None):
    """Use a trained RPN to generate proposals.
    """

    cfg.TEST.RPN_PRE_NMS_TOP_N = -1     # no pre NMS filtering
    cfg.TEST.RPN_POST_NMS_TOP_N = 2000  # limit top boxes after NMS
    print 'RPN model: {}'.format(rpn_model_path)
    print('Using config:')
    pp = pprint.PrettyPrinter(depth=6)
    pp.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    # NOTE: the matlab implementation computes proposals on flipped images, too.
    # We compute them on the image once and then flip the already computed
    # proposals. This might cause a minor loss in mAP (less proposal jittering).
    imdb = get_imdb(imdb_name)
    print 'Loaded dataset `{:s}` for proposal generation'.format(imdb.name)

    # Load RPN and configure output directory
    rpn_net = caffe.Net(rpn_test_prototxt, rpn_model_path, caffe.TEST)
    if output_dir==None:
        output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    # Generate proposals on the imdb
    rpn_proposals = imdb_proposals(rpn_net, imdb)
    # Write proposals to disk and send the proposal file path through the
    # multiprocessing queue
    rpn_net_name = os.path.splitext(os.path.basename(rpn_model_path))[0]
    rpn_proposals_path = os.path.join(
        output_dir, rpn_net_name + ('_'+part_id if part_id != None else '')+'_proposals.pkl')
    with open(rpn_proposals_path, 'wb') as f:
        cPickle.dump(rpn_proposals, f, cPickle.HIGHEST_PROTOCOL)
    print 'Wrote RPN proposals to {}'.format(rpn_proposals_path)
    queue.put({'proposal_path': rpn_proposals_path, 'rpn_net': rpn_net_name}) 
開發者ID:djdam,項目名稱:faster-rcnn-scenarios,代碼行數:39,代碼來源:train.py

示例11: train_fast_rcnn

# 需要導入模塊: from fast_rcnn import config [as 別名]
# 或者: from fast_rcnn.config import get_output_dir [as 別名]
def train_fast_rcnn(queue=None, imdb_name=None, init_model=None, solver=None,
                    max_iters=None, cfg=None, rpn_file=None, output_dir=None):
    """Train a Fast R-CNN using proposals generated by an RPN.
    """

    cfg.TRAIN.HAS_RPN = False           # not generating prosals on-the-fly
    cfg.TRAIN.PROPOSAL_METHOD = 'rpn'   # use pre-computed RPN proposals instead
    cfg.TRAIN.IMS_PER_BATCH = 1
    print 'Init model: {}'.format(init_model)
    print 'RPN proposals: {}'.format(rpn_file)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    roidb, imdb = get_roidb(imdb_name, rpn_file=rpn_file)
    if output_dir==None:
        output_dir = get_output_dir(imdb)

    print 'Output will be saved to `{:s}`'.format(output_dir)
    # Train Fast R-CNN
    model_paths = train_net(solver, roidb, output_dir,
                            pretrained_model=init_model,
                            max_iters=max_iters)
    # Cleanup all but the final model
    for i in model_paths[:-1]:
        os.remove(i)
    fast_rcnn_model_path = model_paths[-1]
    # Send Fast R-CNN model path over the multiprocessing queue
    if queue != None:
        queue.put({'model_path': fast_rcnn_model_path}) 
開發者ID:djdam,項目名稱:faster-rcnn-scenarios,代碼行數:34,代碼來源:train.py


注:本文中的fast_rcnn.config.get_output_dir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。