Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Timer unit: 1e-06 s
- File: cnv.py
- Function: change_input at line 66
- Total time: 743.633 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 66 @profile
- 67 def change_input(self,input1):
- 68 1197 2672 2.2 0.0 self.input=input1
- 69 7182 14739 2.1 0.0 for i in xrange(self.conv_out_shape[1]):
- 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')
- 71 7182 8109 1.1 0.0 for i in xrange(self.pooled_shape[1]):
- 72 41895 38745 0.9 0.0 for j in xrange(self.pooled_shape[2]):
- 73 682290 581325 0.9 0.1 for k in xrange(self.pooled_shape[3]):
- 74 16159500 18610569 1.2 2.5 for l in xrange(self.pooled_shape[4]):
- 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])
- 76
- 77 1197 1674 1.4 0.0 self.output=self.pooled
- File: cnv.py
- Function: gradient at line 81
- Total time: 192.959 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 81 @profile
- 82 def gradient(self,eta):
- 83 5448 5370 1.0 0.0 for i in xrange(len(self.b)):
- 84 31780 38779 1.2 0.0 for j in xrange(len(self.b[i])):
- 85 27240 530038 19.5 0.3 self.b[i][j]-=eta*numpy.asarray(self.delta[0][i][j]).sum()
- 86 908 67064 73.9 0.0 delta1=numpy.asarray(numpy.zeros(self.conv_out_shape))
- 87 5448 5686 1.0 0.0 for i in xrange(self.conv_out_shape[1]):
- 88 31780 44537 1.4 0.0 for j in xrange(self.conv_out_shape[2]):
- 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
- 90
- 91 5448 13082 2.4 0.0 for i in xrange(self.filter_shape[1]):
- 92 4540 115269 25.4 0.1 t=numpy.rot90(delta1[0][i],2)
- 93 4540 188091050 41429.7 97.5 self.W[0][i]-=sg.fftconvolve(self.input[0][0],t,mode='valid')*eta
- File: cnv.py
- Function: change_input at line 125
- Total time: 79.9107 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 125 @profile
- 126 def change_input(self,input1):
- 127 1197 1613 1.3 0.0 self.input=input1
- 128 19152 29871 1.6 0.0 for i in xrange(self.conv_out_shape[1]):
- 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')
- 130 19152 17689 0.9 0.0 for i in xrange(self.pooled_shape[1]):
- 131 71820 77460 1.1 0.1 for j in xrange(self.pooled_shape[2]):
- 132 269325 268317 1.0 0.3 for k in xrange(self.pooled_shape[3]):
- 133 1508220 1913365 1.3 2.4 for l in xrange(self.pooled_shape[4]):
- 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])
- 135
- 136 1197 1652 1.4 0.0 self.output=self.pooled
- File: cnv.py
- Function: gradient at line 141
- Total time: 119.175 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 141 @profile
- 142 def gradient(self,inp,eta):
- 143
- 144 14528 15043 1.0 0.0 for i in xrange(len(self.b)):
- 145 54480 86763 1.6 0.1 for j in xrange(len(self.b[i])):
- 146 40860 776347 19.0 0.7 self.b[i][j]-=eta*numpy.asarray(self.delta[0][i][j]).sum()
- 147 908 11457 12.6 0.0 delta1=numpy.asarray(numpy.zeros(self.conv_out_shape))
- 148 14528 15114 1.0 0.0 for i in xrange(self.conv_out_shape[1]):
- 149 54480 87144 1.6 0.1 for j in xrange(self.conv_out_shape[2]):
- 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
- 151 908 2041 2.2 0.0 self.delta1=delta1
- 152
- 153
- 154 908 9356 10.3 0.0 inp.delta=numpy.zeros(self.image_shape)
- 155 14528 25540 1.8 0.0 for i in xrange(self.conv_out_shape[1]):
- 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')
- 157 908 49218 54.2 0.0 inp.delta/=(self.filter_shape[1]*1.0)
- 158 5448 6957 1.3 0.0 for i in xrange(self.image_shape[1]):
- 159 31780 33179 1.0 0.0 for j in xrange(self.image_shape[2]):
- 160 517560 503099 1.0 0.4 for k in xrange(self.image_shape[3]):
- 161 12258000 13147552 1.1 11.0 for l in xrange(self.image_shape[4]):
- 162 #conv_out[0][i][j][k][l]=de_convolve(inp,i,j,k,l)
- 163 11767680 69576105 5.9 58.4 inp.delta[0][i][j][k][l]*=(1-inp.output[0][i][j][k][l]**2)
- 164 #inp.delta/=self.filter_shape[1]
- 165
- 166 908 897 1.0 0.0 j=0
- 167 908 868 1.0 0.0 k=0
- 168 908 873 1.0 0.0 m=0
- 169 14528 16335 1.1 0.0 for i in xrange(self.conv_out_shape[1]):
- 170 13620 273229 20.1 0.2 ab=numpy.rot90(delta1[0][i],2)
- 171 13620 18873569 1385.7 15.8 k+=numpy.asarray(sg.fftconvolve(self.input[0][j],ab,mode='valid'))
- 172 13620 22673 1.7 0.0 j+=1
- 173 13620 21173 1.6 0.0 if j==self.image_shape[1]:
- 174 #k=k/self.image_shape[1]
- 175 2724 42871 15.7 0.0 self.W[0][m]-=eta*k
- 176 2724 3978 1.5 0.0 m+=1
- 177 2724 2722 1.0 0.0 j=0
- 178 2724 3371 1.2 0.0 k=0
- File: cnv.py
- Function: de_convolve at line 181
- Total time: 0 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 181 @profile
- 182 def de_convolve(self,inp,i,j,k,l):
- 183 kernel_number=int(i/self.image_shape[1])
- 184 channel_number=i%self.image_shape[1]
- 185 for a in xrange(self.filter_shape[2]):
- 186 for b in xrange(self.filter_shape[3]):
- 187 for c in xrange(self.filter_shape[4]):
- 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]
- File: cnv.py
- Function: de_convolve at line 251
- Total time: 0 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 251 @profile
- 252 def de_convolve(self,inp,i,j,k,l):
- 253 kernel_number=int(i/self.image_shape[1])
- 254 channel_number=i%self.image_shape[1]
- 255 # sum=0
- 256 for a in xrange(self.filter_shape[2]):
- 257 for b in xrange(self.filter_shape[3]):
- 258 for c in xrange(self.filter_shape[4]):
- 259 inp.delta[0][channel_number][j+a][k+b][l+c]+=self.delta[i]*self.W[0][kernel_number][a][b][c]
- 260 inp.delta/=(self.filter_shape[1]*1.0)
- File: cnv.py
- Function: gradient at line 314
- Total time: 6.81876 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 314 @profile
- 315 def gradient(self,y,eta):
- 316 908 930 1.0 0.0 delta=[]
- 317 6356 5293 0.8 0.1 for i in xrange(self.n_out):
- 318 5448 37295 6.8 0.5 if y==i:
- 319 908 5202 5.7 0.1 delta.append((self.output[i]-1)*((1-self.output[i])**2))
- 320 #delta.append((1-self.output[i])**2)
- 321 else:
- 322 4540 25522 5.6 0.4 delta.append((self.output[i]+1)*((1-self.output[i])**2))
- 323 #delta.append((1-self.output[i])**2)
- 324 908 1465 1.6 0.0 self.delta=delta
- 325
- 326 908 621 0.7 0.0 delta_prev=[]
- 327 908 577 0.6 0.0 ab=0
- 328 69008 41413 0.6 0.6 for i in xrange(self.n_in):
- 329 476700 381522 0.8 5.6 for j in xrange(self.n_out):
- 330 408600 2341412 5.7 34.3 ab=ab+self.W[i][j]*delta[j]
- 331 68100 336828 4.9 4.9 ab=ab*((1-self.input.output[0][i][0][0][0])**2)
- 332 68100 70695 1.0 1.0 delta_prev.append(ab)
- 333 68100 43713 0.6 0.6 ab=0
- 334 908 5419 6.0 0.1 self.input.delta=delta_prev
- 335 69008 41317 0.6 0.6 for i in xrange(self.n_in):
- 336 476700 403507 0.8 5.9 for j in xrange(self.n_out):
- 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])
- 338 6356 5379 0.8 0.1 for i in xrange(self.n_out):
- 339 5448 29705 5.5 0.4 self.b[i]=self.b[i]-eta*delta[i]
- File: cnv.py
- Function: check at line 340
- Total time: 1326.92 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 340 @profile
- 341 def check(learning_rate=0.005, n_epochs=3,dataset='./kth_thesis.pkl',nkerns=[5,3,5], batch_size=1):
- 342 1 34 34.0 0.0 rng=numpy.random.RandomState(23455)
- 343 1 740 740.0 0.0 f = open('kth_thesis.pkl', 'rb')
- 344 1 221664 221664.0 0.0 train_set, test_set = cPickle.load(f)
- 345 1 485 485.0 0.0 f.close()
- 346 1 2 2.0 0.0 train_set_x, train_set_y=train_set
- 347 1 26908 26908.0 0.0 print train_set
- 348 1 10653 10653.0 0.0 print test_set
- 349 #validate_set_x, validate_set_y=validate_set
- 350 1 3 3.0 0.0 test_set_x, test_set_y=test_set
- 351 1 2 2.0 0.0 n_train_batches = len(train_set_x)
- 352 1 2 2.0 0.0 n_test_batches = len(test_set_x)
- 353 1 16 16.0 0.0 a=numpy.arange(n_train_batches)
- 354 1 686 686.0 0.0 random.shuffle(a)
- 355 1 2 2.0 0.0 k=0
- 356 1 2 2.0 0.0 k1=0
- 357 1 2 2.0 0.0 k2=0
- 358 3 6 2.0 0.0 for n in xrange(2):
- 359 2 10 5.0 0.0 print "training epoch %d" %n
- 360 910 1910 2.1 0.0 for i in xrange(n_train_batches):
- 361 908 12016 13.2 0.0 print a[i]
- 362 908 14285 15.7 0.0 print 'Output is',train_set_y[a[i]]
- 363 908 6712 7.4 0.0 print "training batch %d" %i
- 364 908 1799 2.0 0.0 if n==0 and k==0:
- 365 1 3 3.0 0.0 print "ffff: ",k1
- 366 1 2 2.0 0.0 k1+=1
- 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))
- 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))
- 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))
- 370 1 1451 1451.0 0.0 layer4=LogisticRegession(rng,layer3,nkerns[0]*nkerns[1]*nkerns[2],6)
- 371 1 2 2.0 0.0 k+=1
- 372 else:
- 373 907 2715 3.0 0.0 print "eeee: ",k2
- 374 907 1799 2.0 0.0 k2+=1
- 375 907 590145492 650656.6 44.5 layer1.change_input(numpy.reshape(train_set_x[a[i]],(1,1,9,60,80)))
- 376 907 63298243 69788.6 4.8 layer2.change_input(layer1.output)
- 377 907 35495427 39135.0 2.7 layer3.change_input(layer2.output)
- 378 907 1288181 1420.3 0.1 layer4.change_input(layer3)
- 379 908 8440276 9295.5 0.6 layer4.gradient(train_set_y[a[i]],learning_rate)
- 380 908 64799304 71364.9 4.9 layer3.gradient(layer2,learning_rate)
- 381 908 149343946 164475.7 11.3 layer2.gradient(layer1,learning_rate)
- 382 908 193126568 212694.5 14.6 layer1.gradient(learning_rate)
- 383
- 384
- 385
- 386
- 387 #if n==0 and i==1:
- 388 #print "hi"
- 389 #print layer3.W
- 390 #print "hi"
- 391 #print layer2.output
- 392
- 393 2 4 2.0 0.0 error=0.0
- 394 2 16 8.0 0.0 print "checking errors"
- 395 292 605 2.1 0.0 for i in xrange(n_test_batches):
- 396
- 397 290 187936565 648057.1 14.2 layer1.change_input(numpy.reshape(test_set_x[i],(1,1,9,60,80)))
- 398 290 20230661 69760.9 1.5 layer2.change_input(layer1.output)
- 399 290 11367035 39196.7 0.9 layer3.change_input(layer2.output)
- 400 290 410161 1414.3 0.0 layer4.change_input(layer3)
- 401 290 10899 37.6 0.0 error+=layer4.error(test_set_y[i])
- 402 2 6 3.0 0.0 error_percent=(error/n_test_batches)*100
- 403 #print layer1.W
- 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