Skip to content

Commit 54cd7fb

Browse files
committed
fix the rng seed for caffe (not just numpy); option to randomize training
1 parent 4e50be9 commit 54cd7fb

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ Test output is written underneath `$FRCN_ROOT/output`.
225225
### Experiment scripts
226226
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`.
227227
228+
**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.
229+
Results generated before this commit will have some stochastic variation.
230+
228231
### Extra downloads
229232

230233
- [Experiment logs](http://www.cs.berkeley.edu/~rbg/fast-rcnn-data/fast_rcnn_experiments.tgz)

tools/train_net.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ def parse_args():
2424
Parse input arguments
2525
"""
2626
parser = argparse.ArgumentParser(description='Train a Fast R-CNN network')
27-
parser.add_argument('--gpu', dest='gpu_id', help='GPU device id to use [0]',
27+
parser.add_argument('--gpu', dest='gpu_id',
28+
help='GPU device id to use [0]',
2829
default=0, type=int)
29-
parser.add_argument('--solver', dest='solver', help='solver prototxt',
30+
parser.add_argument('--solver', dest='solver',
31+
help='solver prototxt',
3032
default=None, type=str)
3133
parser.add_argument('--iters', dest='max_iters',
3234
help='number of iterations to train',
@@ -35,10 +37,14 @@ def parse_args():
3537
help='initialize with pretrained model weights',
3638
default=None, type=str)
3739
parser.add_argument('--cfg', dest='cfg_file',
38-
help='optional config file', default=None, type=str)
40+
help='optional config file',
41+
default=None, type=str)
3942
parser.add_argument('--imdb', dest='imdb_name',
4043
help='dataset to train on',
4144
default='voc_2007_trainval', type=str)
45+
parser.add_argument('--rand', dest='randomize',
46+
help='randomize (do not use a fixed seed)',
47+
action='store_true')
4248

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

62-
# fix the random seed for reproducibility
63-
np.random.seed(cfg.RNG_SEED)
68+
if not args.randomize:
69+
# fix the random seeds (numpy and caffe) for reproducibility
70+
np.random.seed(cfg.RNG_SEED)
71+
caffe.set_random_seed(cfg.RNG_SEED)
6472

6573
# set up caffe
6674
caffe.set_mode_gpu()

0 commit comments

Comments
 (0)