Example #1
0
def main():
    # Get args from command line
    args = get_args_from_command_line()
    
    if args.gpu_id is not None:
        cfg.CONST.DEVICE = args.gpu_id
    if not args.randomize:
        np.random.seed(cfg.CONST.RNG_SEED)
    if args.batch_size is not None:
        cfg.CONST.BATCH_SIZE = args.batch_size
    if args.iter is not None:
        cfg.TRAIN.NUM_ITERATION = args.iter
    if args.out_path is not None:
        cfg.DIR.OUT_PATH = args.out_path
    if args.weights is not None:
        cfg.CONST.WEIGHTS = args.weights
        cfg.TRAIN.RESUME_TRAIN = True
        cfg.TRAIN.INITIAL_ITERATION = int(args.init_iter)

    # Print config
    print('Use config:')
    pprint(cfg)

    # Set GPU to use
    theano.gpuarray.use(cfg.CONST.DEVICE)

    # Start train/test process
    if not args.test:
        train_net(cfg)
    else:
        test_net(cfg)
Example #2
0
def main():
    # Get args from command line
    args = get_args_from_command_line()

    if args.gpu_id is not None:
        cfg.CONST.DEVICE = args.gpu_id
    if args.weights is not None:
        cfg.CONST.WEIGHTS = args.weights

    # Print config
    print('Use config:')
    pprint(cfg)

    # Set GPU to use
    os.environ["CUDA_VISIBLE_DEVICES"] = cfg.CONST.DEVICE

    # Start train/test process
    if not args.test and not args.inference:
        train_net(cfg)
    else:
        if 'WEIGHTS' not in cfg.CONST or not os.path.exists(cfg.CONST.WEIGHTS):
            logging.error('Please specify the file path of checkpoint.')
            sys.exit(2)

        if args.test:
            test_net(cfg)
        else:
            inference_net(cfg)
Example #3
0
def main():
    # Get args from command line
    args = get_args_from_command_line()

    if args.gpu_id is not None:
        cfg.CONST.DEVICE = args.gpu_id
    if args.weights is not None:
        cfg.CONST.WEIGHTS = args.weights

    # Print config
    print('Use config:')
    pprint(cfg)
    # f_runner.write(str(cfg))

    # Set GPU to use
    os.environ["CUDA_VISIBLE_DEVICES"] = cfg.CONST.DEVICE

    # Start train/test process
    if not args.test and not args.inference:
        train_net(cfg)
    else:
        '''
        if 'WEIGHTS' not in cfg.CONST or not os.path.exists(cfg.CONST.WEIGHTS):
            logging.error('Please specify the file path of checkpoint.')
            sys.exit(2)
        '''

        if 'WEIGHTS' not in cfg.CONST:
            logging.error('Please specify the file path of checkpoint.1')
            sys.exit(2)
        if not os.path.exists(cfg.CONST.WEIGHTS):
            logging.error('Please specify the file path of checkpoint.2')
            sys.exit(2)

        if args.test:
            # test_net(cfg)
            path = '/raid/wuruihai/GRNet_FILES/tb_log'
            test_writer = SummaryWriter(path)
            test_net(cfg, test_writer=test_writer)

        if args.test_KITTI:
            path = '/raid/wuruihai/GRNet_FILES/tb_log'
            test_writer = SummaryWriter(path)
            test_net_KITTI(cfg, test_writer=test_writer)
        else:
            inference_net(cfg)
Example #4
0
def main():
    # Get args from command line
    args = get_args_from_command_line()

    # Read the experimental config
    exec(compile(open(args.cfg_file, "rb").read(), args.cfg_file, 'exec'))
    cfg = locals()['__C']
    pprint(cfg)

    # Parse runtime arguments
    if args.gpu_id is not None:
        os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu_id
    if not args.randomize:
        random.seed(cfg.CONST.RNG_SEED)
        np.random.seed(cfg.CONST.RNG_SEED)
        torch.manual_seed(cfg.CONST.RNG_SEED)
        torch.cuda.manual_seed(cfg.CONST.RNG_SEED)
        torch.cuda.manual_seed_all(cfg.CONST.RNG_SEED)
        # References: https://pytorch.org/docs/stable/notes/randomness.html
        torch.backends.cudnn.deterministic = True
        torch.backends.cudnn.benchmark = False
    if args.exp_name is not None:
        cfg.CONST.EXP_NAME = args.exp_name
    if args.weights is not None:
        cfg.CONST.WEIGHTS = args.weights

    # Start train/test process
    if not args.test and not args.inference:
        # Make sure cfg.TRAIN.NETWORK in ['RMNet', 'TinyFlowNet']
        if cfg.TRAIN.NETWORK not in ['RMNet', 'TinyFlowNet']:
            logging.error(
                'Please make sure cfg.TRAIN.NETWORK in ["RMNet", "TinyFlowNet"].'
            )
            sys.exit(1)

        train_net(cfg)
    else:
        if 'WEIGHTS' not in cfg.CONST or not os.path.exists(cfg.CONST.WEIGHTS):
            logging.error('Please specify the file path of checkpoint.')
            sys.exit(2)

        if args.test:
            test_net(cfg)
        else:
            inference_net(cfg)
Example #5
0
def main():
    # Get args from command line
    args = get_args_from_command_line()

    if args.gpu_id is not None:
        cfg.CONST.DEVICE = args.gpu_id
    if not args.randomize:
        np.random.seed(cfg.CONST.RNG_SEED)
    if args.batch_size is not None:
        cfg.CONST.BATCH_SIZE = args.batch_size
    if args.epoch is not None:
        cfg.TRAIN.NUM_EPOCHES = args.epoch
    if args.dataset is not None:
        cfg.DATASET.DATASET_NAME = args.dataset
        if cfg.DATASET.DATASET_NAME not in cfg.DATASETS:
            cfg.DATASET.CENTER_BIAS = cfg.DATASETS.TEST.CENTER_BIAS
        else:
            cfg.DATASET.CENTER_BIAS = cfg.DATASETS.SALICON.CENTER_BIAS
    if args.out_path is not None:
        cfg.DIR.OUT_PATH = args.out_path
    if args.weights is not None:
        cfg.CONST.WEIGHTS = args.weights
        if not args.test:
            cfg.TRAIN.RESUME_TRAIN = True

    # print config
    print('Use config:')
    pprint(cfg)

    # Set GPU to use
    if type(cfg.CONST.DEVICE) == str:
        os.environ["CUDA_VISIBLE_DEVICES"] = cfg.CONST.DEVICE

    # Start train/test process
    if not args.test:
        train_net(cfg)
    else:
        if 'WEIGHTS' in cfg.CONST and os.path.exists(cfg.CONST.WEIGHTS):
            test_net(cfg)
        else:
            print('[FATAL] %s Please specify the file path of checkpoint.' %
                  (dt.now()))
            sys.exit(2)
Example #6
0
import dragon.memonger as opt
opt.ShareGrads()

cfg.DATA_DIR = 'data/quad'

if __name__ == '__main__':

    # fix the random seeds (numpy and caffe) for reproducibility
    np.random.seed(cfg.RNG_SEED)
    caffe.set_random_seed(cfg.RNG_SEED)

    # setup caffe
    caffe.set_mode_gpu()
    caffe.set_device(gpu_id)

    # setup database
    cfg.DATABASE = imdb_name
    imdb = get_imdb(imdb_name)
    print 'Database({}): {} images will be used to train.'.format(
        cfg.DATABASE, imdb.db_size)
    output_dir = osp.abspath(osp.join(cfg.ROOT_DIR, 'output', imdb_name))
    print 'Output will be saved to `{:s}`'.format(output_dir)

    # train net
    train_net(solver_txt,
              output_dir,
              pretrained_model=pretrained_model,
              snapshot_model=snapshot_model,
              start_iter=start_iter,
              max_iters=max_iters,
              warm_up=warm_up)
    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 = get_roidb(args.imdb_name)
    print '{:d} roidb entries'.format(len(roidb))
    print("num_classes", imdb.num_classes)
    print(imdb.roidb_num_bboxes_at(-1))
    print(roidb[0])
    sys.exit()

    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)
Example #8
0
            print(sample.keys())
            print(sample['flipped'])
        
    """
    al_net = None
    if args.al_net is not None and args.al_def is not None:
        al_net = caffe.Net(args.al_def, caffe.TEST, weights=args.al_net)
        al_net.name = "al_" + os.path.splitext(os.path.basename(
            args.al_def))[0]

    print '{:d} roidb entries'.format(len(roidb))
    print 'Output will be saved to `{:s}`'.format(output_dir)
    train_net(args.solver,
              roidb,
              output_dir,
              solver_state=args.solver_state,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters,
              al_net=al_net)
'''
argparse.ArgumentParser
Input: (description='Train a Fast R-CNN network'), Output: parser

get_repo_imdb
input: (imdb_name), output: imdb

get_training_roidb
input: (imdb), output: roidb

get_roidb
input: (args.imdb_name), output: imdb, roidb 
Example #9
0
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.exp_dir is not None:
        cfg.EXP_DIR = args.exp_dir

    cfg.GPU_ID = args.gpu_id

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

    np.random.seed(cfg.RNG_SEED)
    caffe.set_random_seed(cfg.RNG_SEED)
    random.seed(cfg.RNG_SEED)

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

    time_suffix = 'train_' + datetime.datetime.now().strftime("%d_%m_%Y_%H_%M")
    output_dir = get_output_dir(time_suffix, None)
    print('Output will be saved to `{:s}`'.format(output_dir))

    train_net(output_dir)