produceInfoGainMatrix.py
Go to the documentation of this file.
1 import sys
2 import caffe
3 import matplotlib
4 import numpy as np
5 import lmdb
6 import argparse
7 import leveldb
8 import ROOT
9 import h5py
10 from collections import defaultdict
11 
12 if __name__ == "__main__":
13  parser = argparse.ArgumentParser()
14  parser.add_argument('--leveldb', type=str, required=True)
15 
16  args = parser.parse_args()
17 
18  count = 0
19 
20  matrix= np.zeros(392, dtype = 'f4' )
21 
22  caffe.set_mode_gpu()
23  db = leveldb.LevelDB(args.leveldb)
24 
25  nEvents=200000
26  for key, value in db.RangeIter():
27  if count > nEvents:
28  break
29 
30  datum = caffe.proto.caffe_pb2.Datum()
31  datum.ParseFromString(value)
32  label = int(datum.label)
33  matrix[label] += 1
34  count +=1
35 
36  print matrix
37 
38  total=0
39  for i in range(0, 392):
40  if matrix[i] < (0.001*count):
41  matrix[i]= (0.001*count)
42 
43  print matrix[i]
44  total=total+matrix[i]*((1./(matrix[i]/count))/(3920.*count))
45  matrix[i]=(1./(matrix[i]/count))/(3920.)
46  print matrix[i]
47  matrix[i]=0.7+(matrix[i])
48  print matrix[i]
49 
50  print total
51  print count
52 
53  print matrix
54 
55  summatrix=np.zeros((392, 392), dtype = 'f4')
56  for i in range(0, 392):
57  summatrix[i][i]=matrix[i]
58 
59  readyForH=summatrix
60 
61  print readyForH
62 
63  print readyForH.shape
64 
65  blob=caffe.io.array_to_blobproto(readyForH.reshape(1,1,392,392))
66 
67  with open('infoGain.binaryproto','wb') as f:
68  f.write(blob.SerializeToString())
procfile open("FD_BRL_v0.txt")