Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import numpy as np
  2.  
  3. height = 2
  4. width = 2
  5. channels = 3
  6.  
  7. # create a fake convolutional feature tensor
  8. in_arr_A = []
  9. for i in range(height*width):
  10.     feature_vector = [i]*channels
  11.     in_arr_A.append(feature_vector)
  12. in_arr_A = np.array(in_arr_A)
  13. in_arr_A = np.reshape(in_arr_A, (height, width, channels))
  14.  
  15. # and make a copy of it
  16. in_arr_B = np.copy(in_arr_A)
  17.  
  18. # create the output array
  19. heatmaps = np.zeros((height, width, height*width))
  20.  
  21. # for each feature vector f in in_arr_A:
  22. for i in range(height):
  23.     for j in range(width):
  24.         f = in_arr_A[i,j,:]
  25.  
  26.         heatmap = np.zeros((height, width))
  27.         # slide f over the entireity of in_arr_B, registering similarity:
  28.         for k in range(height):
  29.             for l in range(width):
  30.                 heatmap[k, l] = np.dot(f, in_arr_B[k, l]) # might want to L2 normalize each vector first...
  31.  
  32.         heatmaps[:,:,i*width+j] = heatmap
  33.  
  34. print heatmaps
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement