In [1]:
import pickle

In [2]:
clas_prune_index = pickle.load(open('activations_res/sorted_index.pkl','r'))

In [3]:
for key, value in clas_prune_index.items():
    print key


2th_acts
9th_acts
3th_acts
6th_acts
8th_acts
7th_acts
12th_acts
4th_acts
5th_acts
13th_acts
11th_acts
10th_acts
1th_acts

In [4]:
import random
random.seed(100) # 100,500,9000

In [5]:
num_featuremaps = [64,64,128,128,256,256,256,512,512,512,512,512,512]

In [6]:
random_prune_index = {}
for index, feature_map in enumerate(num_featuremaps):
    temp_list = range(feature_map)
    random.shuffle(temp_list)
    random_prune_index['%dth_acts'%(index+1)] = temp_list

In [7]:
for key, value in random_prune_index.items():
    print key


2th_acts
9th_acts
3th_acts
6th_acts
8th_acts
7th_acts
12th_acts
10th_acts
5th_acts
13th_acts
11th_acts
4th_acts
1th_acts

In [8]:
listA=clas_prune_index['10th_acts'][:256]

In [9]:
listB=random_prune_index['10th_acts'][:256]

In [10]:
len(set(listA)&set(listB)) / float(len(set(listA) | set(listB))) * 100 # random seed 100


Out[10]:
32.64248704663213

In [15]:
common_featuremaps = set(listA)&set(listB)

In [16]:
print len(common_featuremaps)


126

In [17]:
random_and_clas = common_featuremaps&set(listA[:126])

In [18]:
print len(random_and_clas)


64

In [19]:
print common_featuremaps


set([1, 3, 4, 14, 24, 26, 31, 35, 40, 41, 44, 46, 49, 55, 60, 61, 66, 68, 74, 75, 76, 81, 84, 97, 99, 104, 110, 114, 135, 146, 151, 154, 156, 164, 170, 172, 175, 176, 178, 183, 184, 195, 196, 198, 203, 207, 211, 218, 225, 240, 241, 242, 243, 245, 249, 254, 258, 260, 263, 266, 267, 273, 277, 282, 284, 287, 289, 296, 304, 305, 308, 309, 320, 325, 330, 332, 333, 342, 343, 346, 349, 350, 353, 355, 369, 372, 374, 382, 383, 385, 386, 394, 401, 403, 404, 406, 420, 422, 428, 429, 432, 434, 436, 438, 439, 443, 446, 450, 451, 454, 455, 461, 464, 467, 471, 484, 485, 487, 493, 500, 501, 502, 504, 505, 506, 510])

In [20]:
print listA


[442 241 420  80 378 267 418 349 436 194 273 184 318 246  18   1 375 198
 455 325 285 104 320 304 333 271 296 477 303 503 347 451 471 154 220 447
 203 212 218 207 329 507  44 484  14 253  90  83 208 305 277  45 326 478
 311 176 385  40 411 175 107 448   5 429 257 487  96 317 335 221 114  61
   8  37  64 156 404 211  95 307  32 219  92 195  81 430 386 282  41 498
 499  35 434  46 309 308 403 268 249  86 344 161 343 191 209 287 468 394
  85 461 374 258 450 383 463  24 355 397  48  84 189  75 372 238   3 237
 135 280 370  60 393 396 121 438 251  55 110 321 412 401 446 502  71 504
 275 501  15 439  10 454 476 113 506 169   4  68 284 164 117 510 497 428
 490 346 382   2  76 366 353  73 486 456 283  27  77 464 389 511 483 330
 263  19 178 136 350 225 432  56 369 306  66 146 381 479 279 327  74  49
 288 185 205 130 505 332 376 485 410 266 422 367 261 289 358 342 406 356
 124  88  67 384 443  31 170 172  97 245 260 377 183 100 359 472 339 190
 398 421 122 151 243 467   9  52 126 196 239 493 242  26  99 240 201 500
 324 254 362 292]

In [21]:
print len(listA)


256

In [22]:
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np

In [23]:
activation_method = np.ones([256,100],np.float32)
for index,a in enumerate(listA):
    if a in common_featuremaps:
        activation_method[index] = 0
print activation_method.shape
plt.imshow(activation_method,'gray')


(256, 100)
Out[23]:
<matplotlib.image.AxesImage at 0x7fa065558510>

In [24]:
random.seed(300) # best results
random_prune_index = {}
for index, feature_map in enumerate(num_featuremaps):
    temp_list = range(feature_map)
    random.shuffle(temp_list)
    random_prune_index['%dth_acts'%(index+1)] = temp_list
listA=clas_prune_index['10th_acts'][:256]
listB=random_prune_index['10th_acts'][:256]
common_featuremaps = set(listA)&set(listB)
activation_method = np.ones([256,100],np.float32)
for index,a in enumerate(listA):
    if a in common_featuremaps:
        activation_method[index] = 0
print activation_method.shape
plt.imshow(activation_method,'gray')


(256, 100)
Out[24]:
<matplotlib.image.AxesImage at 0x7fa06543aad0>

In [25]:
random.seed(100) # worst results
random_prune_index = {}
for index, feature_map in enumerate(num_featuremaps):
    temp_list = range(feature_map)
    random.shuffle(temp_list)
    random_prune_index['%dth_acts'%(index+1)] = temp_list
listA=clas_prune_index['10th_acts'][:256]
listB=random_prune_index['10th_acts'][:256]
common_featuremaps = set(listA)&set(listB)
activation_method = np.ones([256,100],np.float32)
for index,a in enumerate(listA):
    if a in common_featuremaps:
        activation_method[index] = 0
print activation_method.shape
plt.imshow(activation_method,'gray')


(256, 100)
Out[25]:
<matplotlib.image.AxesImage at 0x7fa065369e50>

In [35]:
random.seed(300) # worst results
random_prune_index = {}
for index, feature_map in enumerate(num_featuremaps):
    temp_list = range(feature_map)
    random.shuffle(temp_list)
    random_prune_index['%dth_acts'%(index+1)] = temp_list
listA=clas_prune_index['10th_acts'][:256]
listB=random_prune_index['10th_acts'][:256]
common_featuremaps = set(listA)&set(listB)
activation_method = np.ones([256,100],np.float32)
for index,a in enumerate(listA):
    if a in common_featuremaps:
        activation_method[index] = 0
print activation_method.shape
plt.imshow(activation_method,'gray')


(256, 100)
Out[35]:
<matplotlib.image.AxesImage at 0x7fa065314e10>

In [33]:
random.seed(100) # 100,500,9000
for index,i in enumerate([100,600,900]):
    random.seed(i)
    random_prune_index = {}
    for index, feature_map in enumerate(num_featuremaps):
        temp_list = range(feature_map)
        random.shuffle(temp_list)
        random_prune_index['%dth_acts'%(index+1)] = temp_list
    listA=clas_prune_index['10th_acts'][:256]
    listB=random_prune_index['10th_acts'][:256]
    common_featuremaps = set(listA)&set(listB)
    activation_method = np.ones([256,100],np.float32)
    for index,a in enumerate(listA):
        if a in common_featuremaps:
            activation_method[index] = 0
    print activation_method.shape
#     plt.subplot(1,3,index)
    plt.imshow(activation_method,'gray')
    plt.show()


(256, 100)
(256, 100)
(256, 100)

In [34]:
for index,i in enumerate([200,300,400,500,700,800]):
    random.seed(i)
    random_prune_index = {}
    for index, feature_map in enumerate(num_featuremaps):
        temp_list = range(feature_map)
        random.shuffle(temp_list)
        random_prune_index['%dth_acts'%(index+1)] = temp_list
    listA=clas_prune_index['10th_acts'][:256]
    listB=random_prune_index['10th_acts'][:256]
    common_featuremaps = set(listA)&set(listB)
    activation_method = np.ones([256,100],np.float32)
    for index,a in enumerate(listA):
        if a in common_featuremaps:
            activation_method[index] = 0
    print activation_method.shape
#     plt.subplot(1,3,index)
    plt.imshow(activation_method,'gray')
    plt.show()


(256, 100)
(256, 100)
(256, 100)
(256, 100)
(256, 100)
(256, 100)

In [ ]: