Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- height = 2
- width = 2
- channels = 3
- # create a fake convolutional feature tensor
- in_arr_A = []
- for i in range(height*width):
- feature_vector = [i]*channels
- in_arr_A.append(feature_vector)
- in_arr_A = np.array(in_arr_A)
- in_arr_A = np.reshape(in_arr_A, (height, width, channels))
- # and make a copy of it
- in_arr_B = np.copy(in_arr_A)
- # create the output array
- heatmaps = np.zeros((height, width, height*width))
- # for each feature vector f in in_arr_A:
- for i in range(height):
- for j in range(width):
- f = in_arr_A[i,j,:]
- heatmap = np.zeros((height, width))
- # slide f over the entireity of in_arr_B, registering similarity:
- for k in range(height):
- for l in range(width):
- heatmap[k, l] = np.dot(f, in_arr_B[k, l]) # might want to L2 normalize each vector first...
- heatmaps[:,:,i*width+j] = heatmap
- print heatmaps
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement