extractScale.py
Go to the documentation of this file.
1 import sys
2 import numpy as np
3 import leveldb
4 import lmdb
5 import math
6 
7 import caffe
8 from caffe.proto import caffe_pb2
9 
10 if __name__ == "__main__":
11  ldb = "TrainLevelDB"
12  db = leveldb.LevelDB(ldb)
13 
14  datum = caffe_pb2.Datum()
15 
16  means = []
17  variances = []
18 
19  count = 0
20  for key, value in db.RangeIter():
21  datum.ParseFromString(value)
22  label = datum.label
23  data = caffe.io.datum_to_array(datum)
24  logData = np.log( data + 1.0 )
25  tmpMean = np.mean(logData)
26  tmpVar = np.var(logData)
27  means.append(tmpMean)
28  variances.append(tmpVar)
29  if count%10000 == 0:
30  print count, ":", "mean:", tmpMean, "variance:", tmpVar
31  count += 1
32 
33  mean = np.mean( np.array( means ) )
34  rms = math.sqrt( np.mean( np.array( variances ) ) )
35 
36  print "mean:", mean, "rms:", rms
37  print "scale term:", 1.0/rms, "bias term:", -mean/rms