Skip to content

Commit 04f3f88

Browse files
committed
Move to python3 plus update dependencies
1 parent 9500600 commit 04f3f88

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

clustering.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ def calculate_symmetric_dist(app_nearest_neighbors):
9393
for row_no, row_val in enumerate(results):
9494
d[row_no, :] = row_val
9595
d_time = time()-dist_calc_time
96-
print 'Distance calculation time : {}'.format(d_time)
97-
96+
print("Distance calculation time : {}".format(d_time))
9897
return d
9998

10099

@@ -184,7 +183,7 @@ def cluster(descriptor_matrix, n_neighbors=10, thresh=[2]):
184183
clusters = []
185184
for th in thresh:
186185
clusters_th = aro_clustering(app_nearest_neighbors, distance_matrix, th)
187-
print 'N Clusters: {}, thresh: {}'.format(len(clusters_th), th)
186+
print("N Clusters: {}, thresh: {}".format(len(clusters_th), th))
188187
clusters.append({'clusters': clusters_th, 'threshold': th})
189188
return clusters
190189

demo.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def plot_histogram(lfw_dir):
1818
for dirname in dirs:
1919
n_photos = len(os.listdir(os.path.join(root, dirname)))
2020
filecount_dict[dirname] = n_photos
21-
print 'No of unique people: {}'.format(len(filecount_dict.keys()))
21+
print("No of unique people: {}".format(len(filecount_dict.keys())))
2222
df = pd.DataFrame(filecount_dict.items(), columns=['Name', 'Count'])
23-
print 'Singletons : {}\nTwo :{}\n'.format((df['Count'] == 1).sum(),
24-
(df['Count'] == 2).sum())
23+
print("Singletons : {}\nTwo :{}\n".format((df['Count'] == 1).sum(),
24+
(df['Count'] == 2).sum()))
2525
plt.hist(df['Count'], bins=max(df['Count']))
2626
plt.title('Cluster Sizes')
2727
plt.xlabel('No of images in folder')
@@ -63,11 +63,11 @@ def evaluate_clusters(clusters, labels_lookup):
6363
"""
6464
precision, recall = calculate_pairwise_pr(clusters, labels_lookup)
6565
f1_score = 2*precision*recall/(precision+recall)
66-
print 'Precision : {}\nRecall : {}\nf1_score : {}'.format(precision,
66+
print("Precision : {}\nRecall : {}\nf1_score : {}".format(precision,
6767
recall,
6868
f1_score
69-
)
70-
print '---------------------------------------------------------'
69+
))
70+
print("---------------------------------------------------------")
7171
return f1_score
7272

7373

@@ -108,8 +108,8 @@ def create_labels_lookup(labels):
108108

109109
labels_lookup = create_labels_lookup(labels)
110110
for clusters in clusters_thresholds:
111-
print 'No of clusters: {}'.format(len(clusters['clusters']))
112-
print 'Threshold : {}'.format(clusters['threshold'])
111+
print("No of clusters: {}".format(len(clusters['clusters'])))
112+
print("Threshold : {}".format(clusters['threshold']))
113113
f1_score = evaluate_clusters(clusters['clusters'], labels_lookup)
114114
# n_faces = 0
115115
# for c in clusters:

evaluation.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def calculate_pairwise_pr(clusters, labels_lookup):
3333
# Recall:
3434
gt_clusters = defaultdict(list)
3535
# Count the actual number of possible true pairs:
36-
for row_no, label in labels_lookup.iteritems():
36+
for row_no, label in labels_lookup.items():
3737
gt_clusters[label].append(row_no)
3838
true_pairs = 0
39-
for cluster_id, cluster_items in gt_clusters.iteritems():
39+
for cluster_id, cluster_items in gt_clusters.items():
4040
n = len(cluster_items)
4141
true_pairs += n * (n-1)/2.0
42-
print 'Correct Pairs that are in the same cluster:{}'.format(correct_pairs)
43-
print 'Total pairs as per the clusters created: {}'.format(total_pairs)
44-
print 'Total possible true pairs:{}'.format(true_pairs)
42+
print("Correct Pairs that are in the same cluster:{}".format(correct_pairs))
43+
print("Total pairs as per the clusters created: {}".format(total_pairs))
44+
print("Total possible true pairs:{}".format(true_pairs))
4545
precision = float(correct_pairs)/total_pairs
4646
recall = float(correct_pairs)/true_pairs
4747
return precision, recall

setup.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,28 @@
55
find_packages)
66

77
runtime_packages = [
8-
'flask == 0.12.3',
9-
'numpy==1.12.1',
10-
'matplotlib==1.5.2',
11-
'profilehooks==1.9.0',
12-
'pandas==0.20.2',
13-
'scipy==0.19.0'
8+
"Click==7.0",
9+
"cycler==0.10.0",
10+
"Flask==1.1.1",
11+
"itsdangerous==1.1.0",
12+
"Jinja2==2.10.1",
13+
"kiwisolver==1.1.0",
14+
"MarkupSafe==1.1.1",
15+
"matplotlib==3.1.1",
16+
"numpy==1.17.0",
17+
"pandas==0.25.0",
18+
"profilehooks==1.11.0",
19+
"pyparsing==2.4.1.1",
20+
"python-dateutil==2.8.0",
21+
"pytz==2019.1",
22+
"scipy==1.3.0",
23+
"six==1.12.0",
24+
"Werkzeug==0.15.5",
1425
]
1526

1627
setup(
1728
name='approximate-nn-clustering',
18-
version='0.0.1',
29+
version='0.0.2',
1930
description='A modified version of rank order clustering',
2031
author='Varun Suresh',
2132
author_email='[email protected]',

visualize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def create_idx_to_path(lfw_dir):
3232

3333
@app.route('/img/<path:fpath>', methods=['GET'])
3434
def get_img_path(fpath):
35-
print os.path.dirname(fpath), fpath.split('/')[-1]
35+
print(os.path.dirname(fpath), fpath.split('/')[-1])
3636
return send_from_directory(os.path.dirname(fpath),fpath.split('/')[-1])
3737

3838
@app.route('/single_cluster', methods=["GET"])

0 commit comments

Comments
 (0)