Skip to content

Commit

Permalink
n
Browse files Browse the repository at this point in the history
  • Loading branch information
yaolubrain committed Oct 7, 2015
1 parent be50871 commit d290bdc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
22 changes: 11 additions & 11 deletions zero_shot_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
print g_mean.shape, P1.shape, PW3.shape, PW23.shape

wnid_list_unseen = open('imagenet_zero_shot_unseen_wnids.txt', 'r').read().splitlines()
wnid_list_all = open('imagenet.synset.obtain_synset_list', 'r').read().splitlines()
wnid_list_mixed = open('imagenet.synset.obtain_synset_list', 'r').read().splitlines()
wnid2idx_unseen = {}
wnid2idx_all = {}
wnid2idx_mixed = {}
for i in xrange(len(wnid_list_unseen)):
wnid2idx_unseen[wnid_list_unseen[i]] = i
for i in xrange(len(wnid_list_all)):
wnid2idx_all[wnid_list_all[i]] = i
for i in xrange(len(wnid_list_mixed)):
wnid2idx_mixed[wnid_list_mixed[i]] = i

correct_total_unseen = 0
correct_total_all = 0
correct_total_mixed = 0
im_num_total_unseen = 0
im_num_total_all = 0
im_num_total_mixed = 0
for f in glob.glob("*.h5"):
output_file = h5py.File(f, 'r')
output = output_file['prob'][:]
Expand Down Expand Up @@ -72,7 +72,7 @@


#mixed
class_idx = wnid2idx_all[wnid]
class_idx = wnid2idx_mixed[wnid]
D = cdist(P1g, PW23, 'cosine')
pred_20 = np.argsort(D, axis=1)[:,:20]
pred_10 = pred_20[:,:10]
Expand All @@ -89,8 +89,8 @@
pred_file.write("%s %d %d %d %d %d %d\n" % (wnid, im_num, correct_1, correct_2, correct_5, correct_10, correct_20))
pred_file.close()

correct_total_all += correct_20
im_num_total_all += im_num
correct_total_mixed += correct_20
im_num_total_mixed += im_num

print correct_20, im_num,

Expand All @@ -99,8 +99,8 @@
else:
print 0.0,

if im_num_total_all != 0:
print correct_total_all / im_num_total_all
if im_num_total_mixed != 0:
print correct_total_mixed / im_num_total_mixed



Expand Down
32 changes: 16 additions & 16 deletions zero_shot_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import glob
from scipy.spatial.distance import cdist

DIM = 100
DIM = 500

with h5py.File('/home/fs/ylu/Code/cnn_stats/zero_shot_mat_pca_'+str(DIM)+'.h5', 'r') as f:
with h5py.File('zero_shot_mat_pca.h5', 'r') as f:
sm_mean = f['sm_mean'][:]
g_mean = f['g_mean'][:]
W1 = f['W1'][:]
Expand All @@ -18,19 +18,19 @@

print g_mean.shape, P1.shape, PW3.shape, PW23.shape

wnid_list_unseen = open('/home/fs/ylu/Code/cnn_stats/imagenet_zero_shot_unseen_wnids.txt', 'r').read().splitlines()
wnid_list_all = open('/home/fs/ylu/Code/cnn_stats/imagenet.synset.obtain_synset_list', 'r').read().splitlines()
wnid_list_unseen = open('imagenet_zero_shot_unseen_wnids.txt', 'r').read().splitlines()
wnid_list_mixed = open('imagenet.synset.obtain_synset_list', 'r').read().splitlines()
wnid2idx_unseen = {}
wnid2idx_all = {}
wnid2idx_mixed = {}
for i in xrange(len(wnid_list_unseen)):
wnid2idx_unseen[wnid_list_unseen[i]] = i
for i in xrange(len(wnid_list_all)):
wnid2idx_all[wnid_list_all[i]] = i
for i in xrange(len(wnid_list_mixed)):
wnid2idx_mixed[wnid_list_mixed[i]] = i

correct_total_unseen = 0
correct_total_all = 0
correct_total_mixed = 0
im_num_total_unseen = 0
im_num_total_all = 0
im_num_total_mixed = 0
for f in glob.glob("*.h5"):
output_file = h5py.File(f, 'r')
output = output_file['prob'][:]
Expand Down Expand Up @@ -61,7 +61,7 @@
correct_2 = np.sum(pred_2 == class_idx)
correct_1 = np.sum(pred_1 == class_idx)

pred_file = open('pred_unseen_pca_'+str(DIM)+'.txt', 'a')
pred_file = open('pred_unseen_pca.txt', 'a')
pred_file.write("%s %d %d %d %d %d %d\n" % (wnid, im_num, correct_1, correct_2, correct_5, correct_10, correct_20))
pred_file.close()

Expand All @@ -73,7 +73,7 @@


# all
class_idx = wnid2idx_all[wnid]
class_idx = wnid2idx_mixed[wnid]
D = cdist(P1g, PW23, 'cosine')
pred_20 = np.argsort(D, axis=1)[:,:20]
pred_10 = pred_20[:,:10]
Expand All @@ -87,12 +87,12 @@
correct_1 = np.sum(pred_1 == class_idx)


pred_file = open('pred_all_pca_'+str(DIM)+'.txt', 'a')
pred_file = open('pred_mixed_pca.txt', 'a')
pred_file.write("%s %d %d %d %d %d %d\n" % (wnid, im_num, correct_1, correct_2, correct_5, correct_10, correct_20))
pred_file.close()

correct_total_all += correct_20
im_num_total_all += im_num
correct_total_mixed += correct_20
im_num_total_mixed += im_num

print correct_20, im_num,

Expand All @@ -101,8 +101,8 @@
else:
print 0.0,

if im_num_total_all != 0:
print correct_total_all / im_num_total_all
if im_num_total_mixed != 0:
print correct_total_mixed / im_num_total_mixed



Expand Down
30 changes: 15 additions & 15 deletions zero_shot_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

DIM = 500

with h5py.File('/home/fs/ylu/Code/cnn_stats/zero_shot_mat_random_'+str(DIM)+'.h5', 'r') as f:
with h5py.File('zero_shot_mat_random.h5', 'r') as f:
sm_mean = f['sm_mean'][:]
g_mean = f['g_mean'][:]
W1 = f['W1'][:]
Expand All @@ -18,19 +18,19 @@

print g_mean.shape, P1.shape, PW3.shape, PW23.shape

wnid_list_unseen = open('/home/fs/ylu/Code/cnn_stats/imagenet_zero_shot_unseen_wnids.txt', 'r').read().splitlines()
wnid_list_all = open('/home/fs/ylu/Code/cnn_stats/imagenet.synset.obtain_synset_list', 'r').read().splitlines()
wnid_list_unseen = open('imagenet_zero_shot_unseen_wnids.txt', 'r').read().splitlines()
wnid_list_mixed = open('imagenet.synset.obtain_synset_list', 'r').read().splitlines()
wnid2idx_unseen = {}
wnid2idx_all = {}
wnid2idx_mixed = {}
for i in xrange(len(wnid_list_unseen)):
wnid2idx_unseen[wnid_list_unseen[i]] = i
for i in xrange(len(wnid_list_all)):
wnid2idx_all[wnid_list_all[i]] = i
for i in xrange(len(wnid_list_mixed)):
wnid2idx_mixed[wnid_list_mixed[i]] = i

correct_total_unseen = 0
correct_total_all = 0
correct_total_mixed = 0
im_num_total_unseen = 0
im_num_total_all = 0
im_num_total_mixed = 0
for f in glob.glob("*.h5"):
output_file = h5py.File(f, 'r')
output = output_file['prob'][:]
Expand Down Expand Up @@ -60,7 +60,7 @@
correct_2 = np.sum(pred_2 == class_idx)
correct_1 = np.sum(pred_1 == class_idx)

pred_file = open('pred_unseen_random_'+str(DIM)+'.txt', 'a')
pred_file = open('pred_unseen_random.txt', 'a')
pred_file.write("%s %d %d %d %d %d %d\n" % (wnid, im_num, correct_1, correct_2, correct_5, correct_10, correct_20))
pred_file.close()

Expand All @@ -72,7 +72,7 @@


# all
class_idx = wnid2idx_all[wnid]
class_idx = wnid2idx_mixed[wnid]
D = cdist(P1g, PW23, 'cosine')
pred_20 = np.argsort(D, axis=1)[:,:20]
pred_10 = pred_20[:,:10]
Expand All @@ -85,12 +85,12 @@
correct_2 = np.sum(pred_2 == class_idx)
correct_1 = np.sum(pred_1 == class_idx)

pred_file = open('pred_all_random_'+str(DIM)+'.txt', 'a')
pred_file = open('pred_mixed_random.txt', 'a')
pred_file.write("%s %d %d %d %d %d %d\n" % (wnid, im_num, correct_1, correct_2, correct_5, correct_10, correct_20))
pred_file.close()

correct_total_all += correct_20
im_num_total_all += im_num
correct_total_mixed += correct_20
im_num_total_mixed += im_num

print correct_20, im_num,

Expand All @@ -99,8 +99,8 @@
else:
print 0.0,

if im_num_total_all != 0:
print correct_total_all / im_num_total_all
if im_num_total_mixed != 0:
print correct_total_mixed / im_num_total_mixed



Expand Down

0 comments on commit d290bdc

Please sign in to comment.