rajeswar

Untitled

Jul 24th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.54 KB | None | 0 0
  1. Timer unit: 1e-06 s
  2.  
  3. File: cnv.py
  4. Function: change_input at line 66
  5. Total time: 743.633 s
  6.  
  7. Line #      Hits         Time  Per Hit   % Time  Line Contents
  8. ==============================================================
  9.     66                                               @profile
  10.     67                                               def change_input(self,input1):
  11.     68      1197         2672      2.2      0.0          self.input=input1
  12.     69      7182        14739      2.1      0.0          for i in xrange(self.conv_out_shape[1]):
  13.     70      5985     97101856  16224.2     13.1              self.conv_out[0][i]=sg.fftconvolve(self.input[0][i%self.image_shape[1]],numpy.rot90(self.W[0][i/self.image_shape[1]],2),mode='valid')
  14.     71      7182         8109      1.1      0.0          for i in xrange(self.pooled_shape[1]):
  15.     72     41895        38745      0.9      0.0              for j in xrange(self.pooled_shape[2]):
  16.     73    682290       581325      0.9      0.1                  for k in xrange(self.pooled_shape[3]):
  17.     74  16159500     18610569      1.2      2.5                      for l in xrange(self.pooled_shape[4]):
  18.     75  15513120    627273411     40.4     84.4                          self.pooled[0][i][j][k][l]=math.tanh((numpy.sum(self.conv_out[0][i][j][k*3][l*3:(l+1)*3])+numpy.sum(self.conv_out[0][i][j][k*3+1][l*3:(l+1)*3])+numpy.sum(self.conv_out[0][i][j][k*3+2][l*3:(l+1)*3]))/9.0+self.b[i][j])
  19.     76                                                          
  20.     77      1197         1674      1.4      0.0          self.output=self.pooled
  21.  
  22. File: cnv.py
  23. Function: gradient at line 81
  24. Total time: 192.959 s
  25.  
  26. Line #      Hits         Time  Per Hit   % Time  Line Contents
  27. ==============================================================
  28.     81                                               @profile
  29.     82                                               def gradient(self,eta):
  30.     83      5448         5370      1.0      0.0          for i in xrange(len(self.b)):
  31.     84     31780        38779      1.2      0.0              for j in xrange(len(self.b[i])):
  32.     85     27240       530038     19.5      0.3                  self.b[i][j]-=eta*numpy.asarray(self.delta[0][i][j]).sum()
  33.     86       908        67064     73.9      0.0          delta1=numpy.asarray(numpy.zeros(self.conv_out_shape))
  34.     87      5448         5686      1.0      0.0          for i in xrange(self.conv_out_shape[1]):
  35.     88     31780        44537      1.4      0.0              for j in xrange(self.conv_out_shape[2]):
  36.     89     27240      4048554    148.6      2.1                  delta1[0][i][j]=numpy.kron(self.delta[0][i][j],[[1,1,1],[1,1,1],[1,1,1]])/9.0
  37.     90                                                  
  38.     91      5448        13082      2.4      0.0          for i in xrange(self.filter_shape[1]):
  39.     92      4540       115269     25.4      0.1              t=numpy.rot90(delta1[0][i],2)
  40.     93      4540    188091050  41429.7     97.5              self.W[0][i]-=sg.fftconvolve(self.input[0][0],t,mode='valid')*eta
  41.  
  42. File: cnv.py
  43. Function: change_input at line 125
  44. Total time: 79.9107 s
  45.  
  46. Line #      Hits         Time  Per Hit   % Time  Line Contents
  47. ==============================================================
  48.    125                                               @profile
  49.    126                                               def change_input(self,input1):
  50.    127      1197         1613      1.3      0.0          self.input=input1
  51.    128     19152        29871      1.6      0.0          for i in xrange(self.conv_out_shape[1]):
  52.    129     17955     24740572   1377.9     31.0              self.conv_out[0][i]=sg.fftconvolve(self.input[0][i%self.image_shape[1]],numpy.rot90(self.W[0][i/self.image_shape[1]],2),mode='valid')
  53.    130     19152        17689      0.9      0.0          for i in xrange(self.pooled_shape[1]):
  54.    131     71820        77460      1.1      0.1              for j in xrange(self.pooled_shape[2]):
  55.    132    269325       268317      1.0      0.3                  for k in xrange(self.pooled_shape[3]):
  56.    133   1508220      1913365      1.3      2.4                      for l in xrange(self.pooled_shape[4]):
  57.    134   1292760     52860124     40.9     66.1                          self.pooled[0][i][j][k][l]=math.tanh((numpy.sum(self.conv_out[0][i][j][k*3][l*3:(l+1)*3])+numpy.sum(self.conv_out[0][i][j][k*3+1][l*3:(l+1)*3])+numpy.sum(self.conv_out[0][i][j][k*3+2][l*3:(l+1)*3]))/9.0+self.b[i][j])
  58.    135                                                          
  59.    136      1197         1652      1.4      0.0          self.output=self.pooled
  60.  
  61. File: cnv.py
  62. Function: gradient at line 141
  63. Total time: 119.175 s
  64.  
  65. Line #      Hits         Time  Per Hit   % Time  Line Contents
  66. ==============================================================
  67.    141                                               @profile
  68.    142                                               def gradient(self,inp,eta):
  69.    143                                                  
  70.    144     14528        15043      1.0      0.0          for i in xrange(len(self.b)):
  71.    145     54480        86763      1.6      0.1              for j in xrange(len(self.b[i])):
  72.    146     40860       776347     19.0      0.7                  self.b[i][j]-=eta*numpy.asarray(self.delta[0][i][j]).sum()
  73.    147       908        11457     12.6      0.0          delta1=numpy.asarray(numpy.zeros(self.conv_out_shape))
  74.    148     14528        15114      1.0      0.0          for i in xrange(self.conv_out_shape[1]):
  75.    149     54480        87144      1.6      0.1              for j in xrange(self.conv_out_shape[2]):
  76.    150     40860      3514835     86.0      2.9                  delta1[0][i][j]=numpy.kron(self.delta[0][i][j],[[1,1,1],[1,1,1],[1,1,1]])/9.0
  77.    151       908         2041      2.2      0.0          self.delta1=delta1
  78.    152                                                  
  79.    153                                                  
  80.    154       908         9356     10.3      0.0          inp.delta=numpy.zeros(self.image_shape)
  81.    155     14528        25540      1.8      0.0          for i in xrange(self.conv_out_shape[1]):
  82.    156     13620     12053038    885.0     10.1              inp.delta[0][i%self.image_shape[1]]+= sg.fftconvolve(self.delta1[0][i],numpy.rot90(self.W[0][i/self.image_shape[1]],2),'full')
  83.    157       908        49218     54.2      0.0          inp.delta/=(self.filter_shape[1]*1.0)
  84.    158      5448         6957      1.3      0.0          for i in xrange(self.image_shape[1]):
  85.    159     31780        33179      1.0      0.0              for j in xrange(self.image_shape[2]):
  86.    160    517560       503099      1.0      0.4                  for k in xrange(self.image_shape[3]):
  87.    161  12258000     13147552      1.1     11.0                      for l in xrange(self.image_shape[4]):
  88.    162                                                                   #conv_out[0][i][j][k][l]=de_convolve(inp,i,j,k,l)
  89.    163  11767680     69576105      5.9     58.4                          inp.delta[0][i][j][k][l]*=(1-inp.output[0][i][j][k][l]**2)
  90.    164                                                   #inp.delta/=self.filter_shape[1]
  91.    165                                                  
  92.    166       908          897      1.0      0.0          j=0
  93.    167       908          868      1.0      0.0          k=0
  94.    168       908          873      1.0      0.0          m=0
  95.    169     14528        16335      1.1      0.0          for i in xrange(self.conv_out_shape[1]):
  96.    170     13620       273229     20.1      0.2              ab=numpy.rot90(delta1[0][i],2)
  97.    171     13620     18873569   1385.7     15.8              k+=numpy.asarray(sg.fftconvolve(self.input[0][j],ab,mode='valid'))
  98.    172     13620        22673      1.7      0.0              j+=1
  99.    173     13620        21173      1.6      0.0              if j==self.image_shape[1]:
  100.    174                                                           #k=k/self.image_shape[1]
  101.    175      2724        42871     15.7      0.0                  self.W[0][m]-=eta*k
  102.    176      2724         3978      1.5      0.0                  m+=1
  103.    177      2724         2722      1.0      0.0                  j=0
  104.    178      2724         3371      1.2      0.0                  k=0
  105.  
  106. File: cnv.py
  107. Function: de_convolve at line 181
  108. Total time: 0 s
  109.  
  110. Line #      Hits         Time  Per Hit   % Time  Line Contents
  111. ==============================================================
  112.    181                                               @profile        
  113.    182                                               def de_convolve(self,inp,i,j,k,l):
  114.    183                                                   kernel_number=int(i/self.image_shape[1])
  115.    184                                                   channel_number=i%self.image_shape[1]
  116.    185                                                   for a in xrange(self.filter_shape[2]):
  117.    186                                                       for b in xrange(self.filter_shape[3]):
  118.    187                                                           for c in xrange(self.filter_shape[4]):
  119.    188                                                               inp.delta[0][channel_number][j+a][k+b][l+c]+=self.delta1[0][i][j][k][l]*self.W[0][kernel_number][a][b][c]
  120.  
  121. File: cnv.py
  122. Function: de_convolve at line 251
  123. Total time: 0 s
  124.  
  125. Line #      Hits         Time  Per Hit   % Time  Line Contents
  126. ==============================================================
  127.    251                                               @profile
  128.    252                                               def de_convolve(self,inp,i,j,k,l):
  129.    253                                                   kernel_number=int(i/self.image_shape[1])
  130.    254                                                   channel_number=i%self.image_shape[1]
  131.    255                                                   # sum=0
  132.    256                                                   for a in xrange(self.filter_shape[2]):
  133.    257                                                       for b in xrange(self.filter_shape[3]):
  134.    258                                                           for c in xrange(self.filter_shape[4]):
  135.    259                                                               inp.delta[0][channel_number][j+a][k+b][l+c]+=self.delta[i]*self.W[0][kernel_number][a][b][c]
  136.    260                                                   inp.delta/=(self.filter_shape[1]*1.0)
  137.  
  138. File: cnv.py
  139. Function: gradient at line 314
  140. Total time: 6.81876 s
  141.  
  142. Line #      Hits         Time  Per Hit   % Time  Line Contents
  143. ==============================================================
  144.    314                                               @profile
  145.    315                                               def gradient(self,y,eta):
  146.    316       908          930      1.0      0.0          delta=[]
  147.    317      6356         5293      0.8      0.1          for i in xrange(self.n_out):
  148.    318      5448        37295      6.8      0.5              if y==i:
  149.    319       908         5202      5.7      0.1                  delta.append((self.output[i]-1)*((1-self.output[i])**2))
  150.    320                                                           #delta.append((1-self.output[i])**2)
  151.    321                                                       else:
  152.    322      4540        25522      5.6      0.4                  delta.append((self.output[i]+1)*((1-self.output[i])**2))
  153.    323                                                           #delta.append((1-self.output[i])**2)
  154.    324       908         1465      1.6      0.0          self.delta=delta
  155.    325                                                  
  156.    326       908          621      0.7      0.0          delta_prev=[]
  157.    327       908          577      0.6      0.0          ab=0
  158.    328     69008        41413      0.6      0.6          for i in xrange(self.n_in):
  159.    329    476700       381522      0.8      5.6              for j in xrange(self.n_out):
  160.    330    408600      2341412      5.7     34.3                  ab=ab+self.W[i][j]*delta[j]
  161.    331     68100       336828      4.9      4.9              ab=ab*((1-self.input.output[0][i][0][0][0])**2)
  162.    332     68100        70695      1.0      1.0              delta_prev.append(ab)
  163.    333     68100        43713      0.6      0.6              ab=0
  164.    334       908         5419      6.0      0.1          self.input.delta=delta_prev
  165.    335     69008        41317      0.6      0.6          for i in xrange(self.n_in):
  166.    336    476700       403507      0.8      5.9              for j in xrange(self.n_out):
  167.    337    408600      3040948      7.4     44.6                  self.W[i][j]=self.W[i][j] - (eta*self.input.output[0][i][0][0][0]*delta[j])
  168.    338      6356         5379      0.8      0.1          for i in xrange(self.n_out):
  169.    339      5448        29705      5.5      0.4              self.b[i]=self.b[i]-eta*delta[i]
  170.  
  171. File: cnv.py
  172. Function: check at line 340
  173. Total time: 1326.92 s
  174.  
  175. Line #      Hits         Time  Per Hit   % Time  Line Contents
  176. ==============================================================
  177.    340                                           @profile            
  178.    341                                           def check(learning_rate=0.005, n_epochs=3,dataset='./kth_thesis.pkl',nkerns=[5,3,5], batch_size=1):
  179.    342         1           34     34.0      0.0      rng=numpy.random.RandomState(23455)
  180.    343         1          740    740.0      0.0      f = open('kth_thesis.pkl', 'rb')
  181.    344         1       221664 221664.0      0.0      train_set, test_set = cPickle.load(f)
  182.    345         1          485    485.0      0.0      f.close()
  183.    346         1            2      2.0      0.0      train_set_x, train_set_y=train_set
  184.    347         1        26908  26908.0      0.0      print train_set
  185.    348         1        10653  10653.0      0.0      print test_set
  186.    349                                               #validate_set_x, validate_set_y=validate_set
  187.    350         1            3      3.0      0.0      test_set_x, test_set_y=test_set
  188.    351         1            2      2.0      0.0      n_train_batches = len(train_set_x)
  189.    352         1            2      2.0      0.0      n_test_batches = len(test_set_x)
  190.    353         1           16     16.0      0.0      a=numpy.arange(n_train_batches)
  191.    354         1          686    686.0      0.0      random.shuffle(a)
  192.    355         1            2      2.0      0.0      k=0
  193.    356         1            2      2.0      0.0      k1=0
  194.    357         1            2      2.0      0.0      k2=0
  195.    358         3            6      2.0      0.0      for n in xrange(2):
  196.    359         2           10      5.0      0.0          print "training epoch %d" %n
  197.    360       910         1910      2.1      0.0          for i in xrange(n_train_batches):
  198.    361       908        12016     13.2      0.0              print a[i]
  199.    362       908        14285     15.7      0.0              print 'Output is',train_set_y[a[i]]
  200.    363       908         6712      7.4      0.0              print "training batch %d" %i
  201.    364       908         1799      2.0      0.0              if n==0 and k==0:
  202.    365         1            3      3.0      0.0             print "ffff:  ",k1
  203.    366         1            2      2.0      0.0         k1+=1
  204.    367         1       622309 622309.0      0.0                  layer1=First_Convolution(rng,numpy.reshape(train_set_x[a[i]],(1,1,9,60,80)),(1,1,9,60,80),(1,nkerns[0],4,7,9),(3,3))
  205.    368         1        64060  64060.0      0.0                  layer2=Hidden_Convolution(rng,layer1.output,(1,nkerns[0],6,18,24),(1,nkerns[1],4,7,7),(3,3))
  206.    369         1        39311  39311.0      0.0                  layer3=Last_Convolution(rng,layer2.output,(1,nkerns[0]*nkerns[1],3,4,6),(1,nkerns[2],3,4,6),(1,1))
  207.    370         1         1451   1451.0      0.0                  layer4=LogisticRegession(rng,layer3,nkerns[0]*nkerns[1]*nkerns[2],6)
  208.    371         1            2      2.0      0.0                  k+=1
  209.    372                                                       else:
  210.    373       907         2715      3.0      0.0             print "eeee: ",k2
  211.    374       907         1799      2.0      0.0         k2+=1
  212.    375       907    590145492 650656.6     44.5                  layer1.change_input(numpy.reshape(train_set_x[a[i]],(1,1,9,60,80)))
  213.    376       907     63298243  69788.6      4.8                  layer2.change_input(layer1.output)
  214.    377       907     35495427  39135.0      2.7                  layer3.change_input(layer2.output)
  215.    378       907      1288181   1420.3      0.1                  layer4.change_input(layer3)
  216.    379       908      8440276   9295.5      0.6              layer4.gradient(train_set_y[a[i]],learning_rate)
  217.    380       908     64799304  71364.9      4.9              layer3.gradient(layer2,learning_rate)
  218.    381       908    149343946 164475.7     11.3              layer2.gradient(layer1,learning_rate)
  219.    382       908    193126568 212694.5     14.6              layer1.gradient(learning_rate)
  220.    383                                                      
  221.    384                                          
  222.    385                                          
  223.    386                                          
  224.    387                                                       #if n==0 and i==1:
  225.    388                                                           #print "hi"
  226.    389                                                           #print layer3.W
  227.    390                                                           #print "hi"
  228.    391                                                           #print layer2.output
  229.    392                                                          
  230.    393         2            4      2.0      0.0          error=0.0
  231.    394         2           16      8.0      0.0          print "checking errors"
  232.    395       292          605      2.1      0.0          for i in xrange(n_test_batches):
  233.    396                                          
  234.    397       290    187936565 648057.1     14.2              layer1.change_input(numpy.reshape(test_set_x[i],(1,1,9,60,80)))
  235.    398       290     20230661  69760.9      1.5              layer2.change_input(layer1.output)
  236.    399       290     11367035  39196.7      0.9              layer3.change_input(layer2.output)
  237.    400       290       410161   1414.3      0.0              layer4.change_input(layer3)
  238.    401       290        10899     37.6      0.0              error+=layer4.error(test_set_y[i])
  239.    402         2            6      3.0      0.0          error_percent=(error/n_test_batches)*100
  240.    403                                                   #print layer1.W
  241.    404         2           25     12.5      0.0          print "error %% after %d epoch is " %n,error_percent
Advertisement
Add Comment
Please, Sign In to add comment