Skip to content

Commit

Permalink
fix the rng seed for caffe (not just numpy); option to randomize trai…
Browse files Browse the repository at this point in the history
…ning
  • Loading branch information
rbgirshick committed May 1, 2015
1 parent 4e50be9 commit 54cd7fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ Test output is written underneath `$FRCN_ROOT/output`.
### Experiment scripts
Scripts to reproduce the experiments in the paper (*up to stochastic variation*) are provided in `$FRCN_ROOT/experiments/scripts`. Log files for experiments are located in `experiments/logs`.
**Note:** Until recently (commit a566e39), the RNG seed for Caffe was not fixed during training. Now it's fixed, unless `train_net.py` is called with the `--rand` flag.
Results generated before this commit will have some stochastic variation.

### Extra downloads

- [Experiment logs](http://www.cs.berkeley.edu/~rbg/fast-rcnn-data/fast_rcnn_experiments.tgz)
Expand Down
2 changes: 1 addition & 1 deletion caffe-fast-rcnn
18 changes: 13 additions & 5 deletions tools/train_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def parse_args():
Parse input arguments
"""
parser = argparse.ArgumentParser(description='Train a Fast R-CNN network')
parser.add_argument('--gpu', dest='gpu_id', help='GPU device id to use [0]',
parser.add_argument('--gpu', dest='gpu_id',
help='GPU device id to use [0]',
default=0, type=int)
parser.add_argument('--solver', dest='solver', help='solver prototxt',
parser.add_argument('--solver', dest='solver',
help='solver prototxt',
default=None, type=str)
parser.add_argument('--iters', dest='max_iters',
help='number of iterations to train',
Expand All @@ -35,10 +37,14 @@ def parse_args():
help='initialize with pretrained model weights',
default=None, type=str)
parser.add_argument('--cfg', dest='cfg_file',
help='optional config file', default=None, type=str)
help='optional config file',
default=None, type=str)
parser.add_argument('--imdb', dest='imdb_name',
help='dataset to train on',
default='voc_2007_trainval', type=str)
parser.add_argument('--rand', dest='randomize',
help='randomize (do not use a fixed seed)',
action='store_true')

if len(sys.argv) == 1:
parser.print_help()
Expand All @@ -59,8 +65,10 @@ def parse_args():
print('Using config:')
pprint.pprint(cfg)

# fix the random seed for reproducibility
np.random.seed(cfg.RNG_SEED)
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()
Expand Down

0 comments on commit 54cd7fb

Please sign in to comment.