Ejemplo n.º 1
0
def train(stps):
    import _init_paths
    import caffe
    from train_net import combined_roidb
    from fast_rcnn.train import train_net
    from fast_rcnn.config import cfg, get_output_dir
    print "Train with configs:"
    print cfg.TRAIN
    print "Setup:"
    print stps
    gpu_id = stps["GPU_ID"]
    solver = stps["TRAIN"]["SOLVER"]
    iters = stps["TRAIN"]["ITERS"]
    imdb_name = stps["TRAIN"]["IMDB"]
    pretrained_model = stps["TRAIN"]["WEIGHTS"]
    caffe.set_mode_gpu()
    caffe.set_device(gpu_id)
    imdb, roidb = combined_roidb(imdb_name)
    output_dir = get_output_dir(imdb)
    print '{:d} roidb entries'.format(len(roidb))
    print 'Output will be saved to `{:s}`'.format(output_dir)
    train_net(solver,
              roidb,
              output_dir,
              pretrained_model=pretrained_model,
              max_iters=iters)
Ejemplo n.º 2
0
def train(classes,
          cfg_file,
          solver_proto,
          train_prototxt,
          pretrained_model,
          max_iters,
          imdb_name='voc_2007_trainval',
          set_cfgs=None):
    if cfg_file is not None:
        cfg_from_file(cfg_file)
    if set_cfgs is not None:
        cfg_from_list(set_cfgs)
    if train_prototxt is not None:
        aux_tools.change_train_prototxt(
            train_prototxt,
            len(classes) + 1)  # add 1 -- should consider background
    imdb, roidb = combined_roidb(imdb_name, classes)
    print imdb.classes
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(solver_proto,
              roidb,
              output_dir,
              pretrained_model=pretrained_model,
              max_iters=max_iters)
Ejemplo n.º 3
0
def main(args_list):
    args = parse_args(args_list)

    print('Called with args:')
    print(args)

    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    cfg.GPU_ID = args.GPU_ID

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    print 'Setting GPU device %d for training' % cfg.GPU_ID
    caffe.set_mode_gpu()
    caffe.set_device(cfg.GPU_ID)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(args.solver, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Ejemplo n.º 4
0
def train_faster_rcnn(no_pretrained, max_iters):
    """Train a Faster R-CNN network on a region of interest database."""
    # Set pretrained model
    if no_pretrained:
        pretrained_model = None
    else:
        pretrained_model = osp.join(cfg.DATA_DIR, 'imagenet_models',
                                    '{:s}.caffemodel'.format(cfg.MODEL_NAME))
        check_if_exist('Pretrained model', pretrained_model)

    # Change solver if OHEM is used
    postfix = ''
    if cfg.TRAIN.USE_OHEM:
        if cfg.MODEL_NAME != 'VGG16' and \
           cfg.MODEL_NAME != 'ResNet101_bn-scale-merged':

            print('Faster RCNN framework with OHEM does not currently '
                  'support model: {:s} (supported models: VGG16, '
                  'ResNet101_bn-scale-merged).').format(cfg.MODEL_NAME)
            sys.exit()
        else:
            postfix = '_ohem'

    # Check if custom anchors exist and copy them to output dir
    if cfg.CUSTOM_ANCHORS:
        anchor_file = osp.join(cfg.DATA_DIR, cfg.DATASET_NAME,
                               'custom_anchor_boxes', '9_anchor_boxes.txt')
        if not osp.exists(anchor_file):
            print('Custom anchor boxes `{:s}` does not exist.'.format(
                anchor_file))
            print('Generate custom anchor boxes with '
                  'data/data_utils/k_means_anchor_boxes.py')
            sys.exit()

        copy(anchor_file, osp.join(cfg.OUTPUT_DIR, '9_anchor_boxes.txt'))

    # Set solver
    solver = osp.join(cfg.MODELS_DIR, cfg.DATASET_NAME, cfg.METHOD_NAME,
                      cfg.MODEL_NAME, 'solver{}.prototxt'.format(postfix))
    check_if_exist('Solver', solver)

    # Set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(cfg.GPU_ID)

    # Set imdb
    imdb_name = '{:s}_train'.format(cfg.DATASET_NAME)

    imdb = get_imdb(imdb_name)
    print('Loaded dataset `{:s}` for training'.format(imdb.name))
    imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD)
    print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD))
    roidb = get_training_roidb(imdb)

    # Start training
    train_net(solver,
              roidb,
              pretrained_model=pretrained_model,
              max_iters=max_iters)
Ejemplo n.º 5
0
def train_rerank(imdb_name=None, init_model=None, solver=None,
              max_iters=None, cfg=None):
    """
    Train a Region Proposal Network in a separate training process.
    """

    cfg.TRAIN.PROPOSAL_METHOD = 'mat'
    cfg.TRAIN.FG_THRESH = 0.7
    cfg.TRAIN.BG_THRESH_HI = 0.3
    cfg.TRAIN.BG_THRESH_LO = 0.0
    cfg.TRAIN.SNAPSHOT_ITERS = 10000
    print 'Init model: {}'.format(init_model)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    mat_file = os.path.join(cfg.DATA_DIR, 'edge_boxes_data', imdb_name+'.mat')
    roidb, imdb = get_roidb(imdb_name, mat_file=mat_file)
    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)
    print 'Final model: {}'.format(model_paths[-1])
Ejemplo n.º 6
0
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})
Ejemplo n.º 7
0
def train_rpn(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)

    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)
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, None)
    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
    return {'model_path': rpn_model_path}
Ejemplo n.º 9
0
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})
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, None)
    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
    return {'model_path': fast_rcnn_model_path}
Ejemplo n.º 11
0
def train_plain_zf(queue=None,
                   imdb_name=None,
                   init_model=None,
                   solver=None,
                   max_iters=None,
                   cfg=None):
    """Train a plain ZF for face attributes prediction.
    """
    print 'Init model: {}'.format(init_model)
    print('Using config:')
    pprint.pprint(cfg)

    # initialize caffe
    _init_caffe(cfg.GPU_ID)

    roidb, imdb = get_roidb(imdb_name)
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    # Train plain ZF
    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)
    plain_zf_model_path = model_paths[-1]
    # Send plain ZF model path over the multiprocessing queue
    queue.put({'model_path': plain_zf_model_path})
Ejemplo n.º 12
0
def finetune(net_params, roidb, GPU_ID=1):

    solver, train_pt, caffenet, bbox_pred_name, max_iters, output_dir, output_prefix = net_params

    if not os.path.isdir(output_dir):
        os.makedirs(output_dir)
    print 'Trained model will be saved to `{:s}`'.format(output_dir)

    caffe.set_mode_gpu()
    caffe.set_device(GPU_ID)

    train_net(solver,
              roidb,
              output_dir,
              output_prefix,
              pretrained_model=caffenet,
              max_iters=max_iters,
              bbox_pred_name="bbox_pred-coco")
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
    # Applies only to Fast R-CNN bbox regression
    cfg.TRAIN.BBOX_REG = False
    # Roidb handler
    cfg.TRAIN.PROPOSAL_METHOD = 'gt'
    # Batch size
    cfg.TRAIN.IMS_PER_BATCH = cfg.TRAIN.RPN_IMS_PER_BATCH

    print 'Init model: {}'.format(init_model)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    # Roidb & Imdb
    stage_flag = "RPN TRAIN"
    roidb, imdb = get_roidb(imdb_name, stage_flag=stage_flag)
    print 'roidb len: {}'.format(len(roidb))

    # Output directory
    output_dir = get_output_dir(imdb, None)
    print 'Output will be saved to `{:s}`'.format(output_dir)

    # Net & Solver
    # here set image_cls param to be None
    # since rpn training need all images of input dataset
    # but it remains the data bias
    model_paths = train_net(solver,
                            roidb,
                            output_dir,
                            imdb.image_index,
                            None,
                            pretrained_model=init_model,
                            max_iters=max_iters)

    # Cleanup all but the final model
    if cfg.TRAIN.IS_RPN_REMOVE_MODEL:
        for i in model_paths[:-1]:
            if os.path.exists(i) and os.path.isfile(i):
                os.remove(i)
    rpn_model_path = model_paths[-1]

    # Send final model path through the multiprocessing queue
    queue.put({'model_path': rpn_model_path})
Ejemplo n.º 14
0
def main(args_list):
    args = parse_args(args_list)

    print('Called with args:')
    print(args)

    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    cfg.GPU_ID = args.GPU_ID

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    print 'Setting GPU device %d for training' % cfg.GPU_ID
    caffe.set_mode_gpu()
    caffe.set_device(cfg.GPU_ID)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(args.solver,
              roidb,
              output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
def train_fast_rcnn(queue=None, imdb_name=None, init_model=None, solver=None, \
    max_iters=None, cfg=None, rpn_file=None, roidbs_cache_path=None):
    """
  Train a Fast R-CNN using proposals generated by an RPN.
  """
    # not generating prosals on-the-fly
    cfg.TRAIN.HAS_RPN = False
    # use pre-computed RPN proposals instead
    if roidbs_cache_path is not None and len(roidbs_cache_path) > 0:
        cfg.TRAIN.PROPOSAL_METHOD = 'cache_rpn'
    else:
        cfg.TRAIN.PROPOSAL_METHOD = 'rpn'
    cfg.TRAIN.IMS_PER_BATCH = cfg.TRAIN.FAST_RCNN_IMS_PER_BATCH

    print 'Init model: {}'.format(init_model)
    print 'RPN proposals: {}'.format(rpn_file)
    print 'roidbs_cache_path: {}'.format(roidbs_cache_path)
    print 'Using config:'
    print
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    # get roidb
    stage_flag = "FAST_RCNN TRAIN"
    roidb, imdb = get_roidb(imdb_name, rpn_file=rpn_file, stage_flag=stage_flag, \
                            roidbs_cache_path=roidbs_cache_path)
    # get output
    output_dir = get_output_dir(imdb, None)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    # Train Fast R-CNN
    model_paths = train_net(solver,
                            roidb,
                            output_dir,
                            imdb.image_index,
                            imdb.image_cls,
                            pretrained_model=init_model,
                            max_iters=max_iters)
    # Cleanup all but the final model
    if cfg.TRAIN.IS_FAST_RCNN_REMOVE_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})
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)

    _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})
Ejemplo n.º 17
0
def train_rerank(queue=None,
                 imdb_names=None,
                 init_model=None,
                 solver=None,
                 max_iters=None,
                 cfg=None):
    """
    Train a Region Proposal Network in a separate training process.
    """

    cfg.TRAIN.RERANK_PROPOSAL = True
    cfg.TRAIN.PROPOSAL_METHOD = 'mat'
    cfg.TRAIN.IMS_PER_BATCH = 1
    cfg.TRAIN.BATCH_SIZE = 256
    cfg.TRAIN.FG_FRACTION = 0.5
    cfg.TRAIN.FG_THRESH = 0.7
    cfg.TRAIN.BBOX_THRESH = 0.7
    print 'Init model: {}'.format(init_model)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    imdb, roidb = combined_roidb(imdb_names,
                                 mat_folder=cfg.TRAIN.RERANK_PROP_PATH)
    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)
    rerank_model_path = model_paths[-1]
    # Send final model path through the multiprocessing queue
    queue.put({'model_path': rerank_model_path})
Ejemplo n.º 18
0
def train_roi_conv(imdb_name=None,
                   init_model=None,
                   solver=None,
                   max_iter=None,
                   cfg=None):
    """Train a Region Proposal Network in a separate training process.
    """
    #imdb_name: train

    _init_caffe(cfg)

    import caffe
    roidb, imdb = get_roidb(imdb_name)

    from fast_rcnn.train import train_net
    model_paths = train_net(solver,
                            roidb,
                            './',
                            pretrained_model=init_model,
                            max_iters=max_iter)
    print 'Training are finished in train process'
Ejemplo n.º 19
0
def train_detection(queue=None,
                    imdb_names=None,
                    init_model=None,
                    solver=None,
                    max_iters=None,
                    cfg=None,
                    pkl_folder=None):
    """Train a detection network using proposals generated by an RERANK."""

    cfg.TRAIN.RERANK_PROPOSAL = False  # not generating prosals on-the-fly
    cfg.TRAIN.PROPOSAL_METHOD = 'pkl'  # use pre-computed RERANK proposals instead
    cfg.TRAIN.IMS_PER_BATCH = 1
    cfg.TRAIN.BATCH_SIZE = 256
    cfg.TRAIN.FG_FRACTION = 0.25
    cfg.TRAIN.FG_THRESH = 0.5
    cfg.TRAIN.BBOX_THRESH = 0.5
    print 'Init model: {}'.format(init_model)
    print 'RERANK proposals: {}'.format(pkl_folder)
    print('Using config:')
    pprint.pprint(cfg)

    import caffe
    _init_caffe(cfg)

    imdb, roidb = combined_roidb(imdb_names, pkl_folder=pkl_folder)
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    # Train detection network
    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)
    detection_model_path = model_paths[-1]
    # Send detection model path over the multiprocessing queue
    queue.put({'model_path': detection_model_path})
Ejemplo n.º 20
0
def train_rpn(queue=None, imdb_name=None, init_model=None, solver=None,
              max_iters=None, cfg=None, output_cache=None,model_name=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)
    print model_name,output_cache
    final_caffemodel = '/net/wujial/py-R-FCN/models/pascal_voc/ResNet-101/' + model_name + '/'+ 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,model_name = model_name)
        # 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})
Ejemplo n.º 21
0
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})
Ejemplo n.º 22
0
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.

    首先这里初始化了一些配置,比较容易忽略的的是PROPOSAL_METHOD设置成了’gt’,值得一提。
    这个设定是从get_roidb然后追溯到底层数据类pascal-voc得到体现,可以看到imdb(pascal_voc的
    父类)通过roidb_handler来决定用什么方式生成roidb,默认为selective_search,这里用了gt_roidb。
    随后,该函数做了一些训练的准备工作,初始化模型,确定路径等,然后再开始正式训练
    """

    # 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})
Ejemplo n.º 23
0
    print pretrained_caffemodel
    max_iterations = 45000

    cfg_from_file(cfg_file)
    cfg.GPU_ID = 0

    # set up global caffe mode
    np.random.seed(cfg.RNG_SEED)
    caffe.set_random_seed(cfg.RNG_SEED)
    caffe.set_mode_gpu()
    caffe.set_device(0)

    # set up train imdb
    #imdb = pascal_voc_person('person_trainval','2007')
    #imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD)
    
    imdb = caltech(train = 1)
    
    roidb = get_training_roidb(imdb)
    print '{:d} roidb entries'.format(len(roidb))
    
    # setup output result directory
    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)

    # train net
    train_net(train_solver, roidb, output_dir,
              pretrained_model=pretrained_caffemodel,
              max_iters=max_iterations)

Ejemplo n.º 24
0
        cfg_from_list(args.set_cfgs)

    cfg.GPU_ID = args.gpu_id

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(args.solver,
              roidb,
              output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters,
              test_during_train=args.test_during_train,
              test_gpu=args.test_gpu,
              test_imdb=args.test_imdb)
Ejemplo n.º 25
0
    # the map from dataset name to the dataset is set and store in the /datasets/factory.py
    # guess that factory.py should run first
    imdb = get_imdb(args.imdb_name)
    print 'Loaded dataset `{:s}` for training'.format(imdb.name)

    #**************************************
    # load original images and groundtruth
    #**************************************
    roidb = get_training_roidb(imdb)

    if cfg.DEBUG:
        for key in roidb[0]:
            print key
        
    # output_dir = get_output_dir(imdb, None)
    output_dir = "/z/home/chsiyuan/Documents/542FinalProject/experiments/results/train"
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    print 'Output will be saved to `{:s}`'.format(output_dir)

    device_name = '/{}:{:d}'.format(args.device,args.device_id)
    print device_name

    network = get_network(args.network_name)
    print 'Use network `{:s}` in training'.format(args.network_name)

    train_net(network, imdb, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Ejemplo n.º 26
0
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    cfg.GPU_ID = args.gpu_id

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(args.solver, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters,
              previous_state=args.previous_state
              )
Ejemplo n.º 27
0
    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    # Filter out images without rois
    roidb = [roi for roi in roidb if len(roi['gt_classes']) != 0]

    if 'ObjectNet3D' in args.imdb_name:
        db_naming = 'objectnet'
    else:
        db_naming = '3Dplus'

    train_net(args.solver,
              roidb,
              output_dir,
              db_naming,
              args.network_specific,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Ejemplo n.º 28
0
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    cfg.GPU_ID = args.gpu_id

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)
    if args.debug:
        caffe.SGDSolver(args.solver)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

    output_dir = get_output_dir(imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    if not cfg.DEBUG:
        cfg.DEBUG = args.debug

    train_net(args.solver, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters, reload=args.reload, gpu_id = args.gpu_id)
Ejemplo n.º 29
0
    # import pdb; pdb.set_trace()
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    print ("Using config:")
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_device(cfg.GPU_ID)
    caffe.set_mode_gpu()

    # import pdb; pdb.set_trace()
    # image_path_prefix = '/storage/product/detection/11st_Bag'
    # loader = eleven_12cat_bag(image_path_prefix, 'train')
    image_path_prefix = "/storage/product/detection/11st_All"
    loader = eleven_all(image_path_prefix, "train")
    output_dir = get_output_dir(loader, None)
    print "Output will be saved to `{:s}`".format(output_dir)
    sys.stdout.flush()

    train_net(
        cfg.TRAIN.SOLVER_PROTOTXT, loader, output_dir, pretrained_model=cfg.TRAIN.CAFFE_MODEL, max_iters=args.max_iters
    )
Ejemplo n.º 30
0
    #import pdb; pdb.set_trace()
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_device(cfg.GPU_ID)
    caffe.set_mode_gpu()

    #import pdb; pdb.set_trace()
    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

    output_dir = get_output_dir(imdb, None)
    print 'Output will be saved to `{:s}`'.format(output_dir)
    sys.stdout.flush()

    train_net(cfg.TRAIN.SOLVER_PROTOTXT, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Ejemplo n.º 31
0
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
    #imdb = get_imdb(args.imdb_name)
    imdb = load_data(args.imdb_name)
    print 'Loaded dataset `{:s}` for training'.format(imdb.name)
    roidb = get_training_roidb(imdb)

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

    device_name = '/{}:{:d}'.format(args.device, args.device_id)
    print device_name

    network = get_network(args.network_name)
    print 'Use network `{:s}` in training'.format(args.network_name)

    train_net(network,
              imdb,
              roidb,
              output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Ejemplo n.º 32
0
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    cfg.GPU_ID = args.gpu_id

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    #caffe.set_mode_gpu()
    caffe.set_mode_cpu()
    # caffe.set_device(args.gpu_id)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(args.solver, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Ejemplo n.º 33
0
        cfg_from_list(args.set_cfgs)

    cfg.GPU_ID = args.gpu_id

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)

    imdbt, roidbt = combined_roidb(args.timdb_name)
    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(args.solver,
              roidb,
              roidbt,
              output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters,
              snapshot=args.snapshot)
Ejemplo n.º 34
0
    
    # set up global varibles for validation
    validation_network = sys.path[4]+'/'+ 'models/pascal_voc_person/VGG16/test.prototxt'
    validation_imdb = inria(test = 1)

    # set up global caffe mode
    cfg_file = sys.path[4] + '/' + 'models/pascal_voc_person/VGG16/vgg16_faster_rcnn.yml'
    
    if 1:
        train_solver = 'models/pascal_voc_person/VGG16/solver.prototxt'
        pretrained_caffemodel = 'data/imagenet_models/VGG16.caffemodel'
        validation_network = 'models/pascal_voc_person/VGG16/test.prototxt'
        cfg_file = 'models/pascal_voc_person/VGG16/vgg16_faster_rcnn.yml'
    
    cfg_from_file(cfg_file)
    
    np.random.seed(cfg.RNG_SEED)
    caffe.set_random_seed(cfg.RNG_SEED)
    caffe.set_mode_gpu()
    caffe.set_device(0)

    # setup output result directory
    output_dir = get_output_dir(train_imdb)
    print 'Output will be saved to `{:s}`'.format(output_dir)

    # train net
    train_net(train_solver, roidb, output_dir,
              pretrained_model=pretrained_caffemodel,
              max_iters=max_iterations,validation_cfg = (validation_network,validation_imdb))

Ejemplo n.º 35
0
    print('Called with args:')
    print(args)

    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    if args.gpu_id is not None:
        caffe.set_device(args.gpu_id)

    imdb = get_imdb(args.imdb_name)
    print 'Loaded dataset `{:s}` for training'.format(imdb.name)
    roidb = get_training_roidb(imdb)

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

    train_net(args.solver, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters,previous_state=args.previous_state)
Ejemplo n.º 36
0
    if args.imdb_name.startswith('sz_veh') or args.imdb_name.startswith(
            'sz_cyc') or args.imdb_name.startswith(
                'sz_ped') or args.imdb_name.startswith('sz_lights'):
        n_classes = 2
    elif args.imdb_name.startswith('ksz_veh') or args.imdb_name.startswith(
            'ksz_cyc') or args.imdb_name.startswith(
                'ksz_ped') or args.imdb_name.startswith('ksz_lights'):
        n_classes = 2
    elif args.imdb_name.startswith('sz'):
        n_classes = 5
    elif args.imdb_name.startswith('voc'):
        n_classes = 21
    else:
        raise Exception('Give me the correct n_classes of %s' %
                        (args.imdb_name))

    assert len(imdb._classes) == n_classes

    logging.info('----------------Use %d classes-----------------' % n_classes)
    network = get_network(args.network_name, n_classes)
    print 'Use network `{:s}` in training'.format(args.network_name)

    train_net(network,
              imdb,
              roidb,
              output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters,
              checkpoint=args.checkpoint)
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)

    imdb, roidb_ori = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb_ori))

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

    caffemodel = train_net(args.solver,
                           roidb_ori,
                           output_dir,
                           pretrained_model=args.pretrained_model,
                           max_iters=args.max_iters)

    #caffemodel = ['/home/chenyang/py-faster-rcnn/output/faster_rcnn_end2end/train/zf_faster_rcnn_iter_10000.caffemodel']
    #caffemodel = ['/home/chenyang/py-faster-rcnn/output/faster_rcnn_end2end/train/zf_HNL_4cls.caffemodel']
    #caffemodel = ['/home/chenyang/py-faster-rcnn/output/faster_rcnn_end2end/train/HNL_zf_iter_10000.caffemodel']
    # Do hard negative learning

    imgs = [
        os.path.join(imdb._data_path, 'Images', x + '.jpg')
        for x in imdb._image_index
    ]

    log_file = '/home/chenyang/lib/log/result_5cls_1113_HNM.txt'
    iters = 1
Ejemplo n.º 38
0
    if len(roidbs) > 1:
        for r in roidbs[1:]:
            roidb.extend(r)
        imdb = datasets.imdb.imdb(imdb_names)
    else:
        imdb = get_imdb(imdb_names)
    return imdb, roidb


if __name__ == '__main__':
    args = parse_args()

    print('Called with args:')
    print(args)

    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    print('Using config:')
    pprint.pprint(cfg)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(roidb, output_dir, max_iters=args.max_iters)
Ejemplo n.º 39
0
    if len(roidbs) > 1:
        for r in roidbs[1:]:
            roidb.extend(r)
        imdb = datasets.imdb.imdb(imdb_names)
    else:
        imdb = get_imdb(imdb_names)
    return imdb, roidb

if __name__ == '__main__':
    args = parse_args()

    print('Called with args:')
    print(args)

    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    print('Using config:')
    pprint.pprint(cfg)

    imdb, roidb = combined_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))

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

    train_net(roidb, output_dir,
              max_iters=args.max_iters)
        roidb = fast_rcnn_train.get_training_roidb(imdb)
        output_dir = fast_rcnn_config.get_output_dir(imdb, None)
        print 'Output will be saved to `{:s}`'.format(output_dir)

        ### mix anothor dataset
        if args.mix_imdb_name != None:
            imdb_mix = get_imdb(args.mix_imdb_name)
            print 'Loaded dataset `{:s}` for training'.format(imdb_mix.name)
            imdb_mix = test_rpn_net.imdb_append_proposals(train_cfg.stage1.test_net, 
                    train_cfg.stage1.model_path.format(imdb.name), imdb_mix, anchors_file)
            roidb_mix = fast_rcnn_train.get_training_roidb(imdb_mix)
            roidb.extend(roidb_mix)
        ### 
 
        stage2_model = fast_rcnn_train.train_net(train_cfg.stage2.solver, 
                  roidb, output_dir, final_name=imdb.name,
                  pretrained_model=train_cfg.common.pretrained_model,
                  max_iters=train_cfg.stage2.max_iters)
        print 'Stage-2: training fast-rcnn finished!'
        
        print 're-store stage-2 final model...'
        dest_path = train_cfg.stage2.model_path.format(imdb.name)
        os.system('cp {:s} {:s}'.format(stage2_model, dest_path))
        print 'done!'
        print 'stage-2 done!'
        
# =============== stage-3 training rpn (fc layers) with fast r-cnn parameters
    if current_stage <= 3:
        print 'start stage-3...'
        imdb = get_imdb(args.imdb_name)
        print 'Loaded dataset `{:s}` for training'.format(imdb.name)
        
Ejemplo n.º 41
0
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    if args.set_cfgs is not None:
        cfg_from_list(args.set_cfgs)

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    if args.gpu_id is not None:
        caffe.set_device(args.gpu_id)

    imdb = get_imdb(args.imdb_name)
    print 'Loaded dataset `{:s}` for training'.format(imdb.name)
    roidb = get_training_roidb(imdb)

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

 #   roidb_s,roidb_w, = weakly_supervised_roidb(roidb) 

    train_net(args.solver, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Ejemplo n.º 42
0
        model_name = 'GOOGLENET4'
    elif 'GOOGLENET5' in model_name:
        model_name = 'GOOGLENET5'
    elif 'GOOGLENET' in model_name:
        model_name = 'GOOGLENET'
    elif 'INCEPTION' in model_name:
        model_name = 'GOOGLENET_BN'
    else:
        raise Exception("This model is not supported. %s" % model_name)
    
    cfg.MODEL_NAME = model_name

    imdb = get_imdb(args.imdb_name, model_to_use, proposal, proposal_file)
    print 'Loaded dataset `{:s}` for training'.format(imdb.name)
    
    # DJDJ
    #imdb.rpn_train_roidb()
    
    roidb = get_training_roidb(imdb, args.model_to_use, args.proposal_file)

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

    train_net(args.solver, imdb.bbox_means, imdb.bbox_stds, roidb, output_dir,
              proposal_file,
              pretrained_model=args.pretrained_model,
              restore=args.restore,
              max_iters=args.max_iters,
              model_to_use=model_to_use,
              proposal=proposal)