我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用caffe.set_random_seed()。
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_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 run(self): """This method runs in the new process.""" global logger setup_exceptions() logger = log_utils.setup_logger('tile_worker') if self.caffe_path is not None: sys.path.append(self.caffe_path + '/python') if self.device >= 0: os.environ['CUDA_VISIBLE_DEVICES'] = str(self.device) import caffe if self.device >= 0: caffe.set_mode_gpu() else: caffe.set_mode_cpu() caffe.set_random_seed(0) np.random.seed(0) self.model = CaffeModel(*self.model_info) self.model.img = np.zeros((3, 1, 1), dtype=np.float32) while True: try: self.process_one_request() except KeyboardInterrupt: break
def rpn_generate(gpus, queue=None, imdb_name=None, rpn_model_path=None, cfg=None, rpn_test_prototxt=None): """Use a trained RPN to generate proposals. """ def rpn_generate_signle_gpu(rank): cfg.GPU_ID=gpus[rank] print('Using config:') pprint.pprint(cfg) import caffe 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) # Load RPN and configure output directory rpn_net = caffe.Net(rpn_test_prototxt, rpn_model_path, caffe.TEST) # Generate proposals on the imdb rpn_proposals = imdb_proposals(rpn_net, imdb, rank, len(gpus), output_dir) 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) imdb = get_imdb(imdb_name) output_dir = os.path.join(get_output_dir(imdb), "proposals") if not os.path.exists(output_dir): os.makedirs(output_dir) print 'Output will be saved to `{:s}`'.format(output_dir) # 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). print 'Loaded dataset `{:s}` for proposal generation'.format(imdb.name) procs=[] for rank in range(len(gpus)): p = mp.Process(target=rpn_generate_signle_gpu, args=(rank, )) p.daemon = True p.start() procs.append(p) for p in procs: p.join() queue.put({'proposal_path': output_dir})