我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用fast_rcnn.config.cfg.RNG_SEED。
def __init__(self, cls, dim, feature_scale=1.0, C=0.001, B=10.0, pos_weight=2.0): self.pos = np.zeros((0, dim), dtype=np.float32) self.neg = np.zeros((0, dim), dtype=np.float32) self.B = B self.C = C self.cls = cls self.pos_weight = pos_weight self.dim = dim self.feature_scale = feature_scale self.svm = svm.LinearSVC(C=C, class_weight={1: 2, -1: 1}, intercept_scaling=B, verbose=1, penalty='l2', loss='l1', random_state=cfg.RNG_SEED, dual=True) self.pos_cur = 0 self.num_neg_added = 0 self.retrain_limit = 2000 self.evict_thresh = -1.1 self.loss_history = []
def init_detection_net(self, gpu_id=0, prototxt=None, caffemodel=None): """init extraction network""" cfg.TEST.HAS_RPN = True # Use RPN for proposals if prototxt is None: prototxt = os.path.join(cfg.ROOT_DIR, 'models', NETS['zf'][0], 'faster_rcnn_alt_opt', 'faster_rcnn_test.pt') if caffemodel is None: caffemodel = os.path.join(cfg.ROOT_DIR, 'output/default/train', NETS['zf'][1]) if not os.path.isfile(caffemodel): raise IOError(('{:s} not found.\nDid you run ./data/script/' 'fetch_faster_rcnn_models.sh?').format(caffemodel)) #np.random.seed(cfg.RNG_SEED) caffe.set_random_seed(cfg.RNG_SEED) caffe.set_mode_gpu() caffe.set_device(gpu_id) self.net_d = caffe.Net(prototxt, caffemodel, caffe.TEST)
def __init__(self, queue, roidb, num_classes): super(BlobFetcher, self).__init__() self._queue = queue self._roidb = roidb self._num_classes = num_classes self._perm = None self._cur = 0 self._shuffle_roidb_inds() # fix the random seed for reproducibility np.random.seed(cfg.RNG_SEED)
def _init_caffe(cfg): """Initialize pycaffe in a training process. """ import caffe # 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(cfg.GPU_ID)
def train_net(solver_prototxt, roidb, output_dir, nccl_uid, gpus, rank, queue, bbox_means, bbox_stds, pretrained_model=None, max_iters=40000): """Train a Fast R-CNN network.""" caffe.set_mode_gpu() caffe.set_device(gpus[rank]) caffe.set_solver_count(len(gpus)) caffe.set_solver_rank(rank) caffe.set_multiprocess(True) caffe.set_random_seed(cfg.RNG_SEED) sw = SolverWrapper(solver_prototxt, roidb, output_dir, nccl_uid, rank, bbox_means, bbox_stds, pretrained_model=pretrained_model) model_paths = sw.train_model(max_iters) if rank==0: queue.put(model_paths)
def train_rpn(gpus, 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 cfg.TRAIN.REAL_BATCH_SIZE = 8 cfg.TRAIN.VAL_PER_BATCH_SIZE = 1 np.random.seed(cfg.RNG_SEED) 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_multi_gpus(solver, roidb, output_dir, gpus, 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})