diff options
author | Vasil Zlatanov <vasko@e4-pattern-vm.europe-west4-a.c.electric-orbit-223819.internal> | 2018-12-05 18:39:52 +0000 |
---|---|---|
committer | Vasil Zlatanov <vasko@e4-pattern-vm.europe-west4-a.c.electric-orbit-223819.internal> | 2018-12-05 18:39:52 +0000 |
commit | 689ab1f6e0f9923d06507d6835f2d0d068a83d22 (patch) | |
tree | 704207204665392c2c95d847306ffabb96cc8dd7 | |
parent | 0066c5e6d027713e94dff750828eba9d72f0ea47 (diff) | |
download | vz215_np1915-689ab1f6e0f9923d06507d6835f2d0d068a83d22.tar.gz vz215_np1915-689ab1f6e0f9923d06507d6835f2d0d068a83d22.tar.bz2 vz215_np1915-689ab1f6e0f9923d06507d6835f2d0d068a83d22.zip |
Replace verbose with logging
-rwxr-xr-x | evaluate.py | 15 | ||||
-rw-r--r-- | lib/kmean.py | 2 | ||||
-rw-r--r-- | lib/rerank.py | 5 |
3 files changed, 14 insertions, 8 deletions
diff --git a/evaluate.py b/evaluate.py index ace647f..76ee472 100755 --- a/evaluate.py +++ b/evaluate.py @@ -31,6 +31,8 @@ from scipy.spatial.distance import cdist sys.path.append('lib') from rerank import re_ranking from kmean import create_kmean_clusters +import logging +from logging import debug parser = argparse.ArgumentParser() parser.add_argument("-t", "--train", help="Use test data instead of query", action='store_true') @@ -53,10 +55,8 @@ parser.add_argument("--data", help="Data folder with features data", default='da args = parser.parse_args() - -def verbose(*text): - if args.verbose: - print(text) +if args.verbose: + logging.basicConfig(level=logging.DEBUG) def draw_results(test_label, pred_label): acc_sc = accuracy_score(test_label, pred_label) @@ -72,8 +72,8 @@ def draw_results(test_label, pred_label): def test_model(gallery_data, probe_data, gallery_label, probe_label, gallery_cam, probe_cam, showfiles_train, showfiles_test, args): - verbose("probe shape:", probe_data.shape) - verbose("gallery shape:", gallery_data.shape) + debug("probe shape:", probe_data.shape) + debug("gallery shape:", gallery_data.shape) if args.rerank: distances = re_ranking(probe_data, gallery_data, @@ -137,6 +137,7 @@ def test_model(gallery_data, probe_data, gallery_label, probe_label, gallery_cam return target_pred def main(): + logging.debug("Verbose mode is on") mat = scipy.io.loadmat(os.path.join(args.data,'cuhk03_new_protocol_config_labeled.mat')) camId = mat['camId'] filelist = mat['filelist'] @@ -167,9 +168,11 @@ def main(): test_table = np.arange(1, args.multrank+1) if (args.normalise): + debug("Normalising data") train_data = np.divide(train_data,LA.norm(train_data, axis=0)) test_data = np.divide(test_data, LA.norm(test_data, axis=0)) if(args.kmean): + debug("Using Kmeans") train_data, train_label, train_cam = create_kmean_clusters(feature_vectors, labels, gallery_idx, diff --git a/lib/kmean.py b/lib/kmean.py index 58309bc..f041b19 100644 --- a/lib/kmean.py +++ b/lib/kmean.py @@ -1,3 +1,4 @@ +from logging import debug import numpy as np from sklearn.cluster import KMeans @@ -39,6 +40,7 @@ def create_kmean_clusters(feature_vectors, labels, gallery_idx, camId): cllab.append(km_labels[i][j]) train_data = np.array(cl) + debug("Kmean data has shape", train_data.shape) train_label = np.array(cllab) train_cam = np.array([clustercam[i] for i in range(2)]).reshape(train_label.shape[0]) return train_data, train_label, train_cam diff --git a/lib/rerank.py b/lib/rerank.py index 6b20f53..6fb5b7b 100644 --- a/lib/rerank.py +++ b/lib/rerank.py @@ -1,5 +1,6 @@ from scipy.spatial.distance import cdist import numpy as np +from logging import debug def re_ranking(probFea,galFea,k1,k2,lambda_value, MemorySave = False, Minibatch = 2000): @@ -7,7 +8,7 @@ def re_ranking(probFea,galFea,k1,k2,lambda_value, MemorySave = False, Minibatch all_num = query_num + galFea.shape[0] feat = np.append(probFea,galFea,axis = 0) feat = feat.astype(np.float16) - print('computing original distance') + debug('computing original distance') if MemorySave: original_dist = np.zeros(shape = [all_num,all_num],dtype = np.float16) i = 0 @@ -29,7 +30,7 @@ def re_ranking(probFea,galFea,k1,k2,lambda_value, MemorySave = False, Minibatch initial_rank = np.argsort(original_dist).astype(np.int32) - print('starting re_ranking') + debug('starting re_ranking') for i in range(all_num): # k-reciprocal neighbors forward_k_neigh_index = initial_rank[i,:k1+1] |