%%javascript
IPython.OutputArea.auto_scroll_threshold = 9999;
import pandas as pd
import numpy as np
from collections import Counter
from matplotlib import pyplot as plt
import os
import cv2
%matplotlib inline
def load_filepaths():
imdir_ideology = 'ideology_image_dataset/'
ideology_files=os.listdir('ideology_image_dataset/')
ideology_files_path=[os.path.join(imdir_ideology,file) for file in ideology_files ]
return ideology_files_path
ideology_files_path=load_filepaths()
len(ideology_files_path)
def showClustering(predicted_labels,label):
label_indexs= np.where(predicted_labels==label)[0]
print("CLUSTER--> ",label,"TOTAL IMAGES--> ",len(label_indexs))
if(len(label_indexs)>=500):
fig=plt.figure(figsize=(10, 400))
elif(len(label_indexs)>100 and len(label_indexs)<500):
fig=plt.figure(figsize=(10, 70))
elif(len(label_indexs)>=50 and len(label_indexs)<100):
fig=plt.figure(figsize=(10, 30))
elif(len(label_indexs)>=20 and len(label_indexs)<50):
fig=plt.figure(figsize=(10, 20))
elif(len(label_indexs)>=0 and len(label_indexs)<20):
fig=plt.figure(figsize=(10, 8))
for i,index in enumerate(label_indexs):
image = cv2.imread(ideology_files_path[index])
image= cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
columns = 4
rows = np.ceil(len(label_indexs)/float(columns))
fig.add_subplot(rows,columns, i+1)
plt.imshow(image)
plt.show()
results_df=pd.read_csv('image-results-hier/ideology_model_resnet50.npy-tsne.csv')
results_df
Unnamed: 0 | n_clusters | silhouette | calinski | davies | |
---|---|---|---|---|---|
0 | Birch | 1009 | 0.341915 | 679.461297 | 0.688316 |
1 | Agglomerative clustering | 839 | 0.424048 | 819.600883 | 0.670247 |
predicted_Labels=np.load('image-results-hier/ideology_model_resnet50.npy-tsne_agg_labels.npy')
unique_labels=set(predicted_Labels)
for label in unique_labels:
if(label!=-1):
showClustering(predicted_Labels,label)
CLUSTER--> 0 TOTAL IMAGES--> 4
CLUSTER--> 1 TOTAL IMAGES--> 6
CLUSTER--> 2 TOTAL IMAGES--> 6
CLUSTER--> 3 TOTAL IMAGES--> 5
CLUSTER--> 4 TOTAL IMAGES--> 4
CLUSTER--> 5 TOTAL IMAGES--> 5
CLUSTER--> 6 TOTAL IMAGES--> 5
CLUSTER--> 7 TOTAL IMAGES--> 4
CLUSTER--> 8 TOTAL IMAGES--> 6
CLUSTER--> 9 TOTAL IMAGES--> 8
CLUSTER--> 10 TOTAL IMAGES--> 4
CLUSTER--> 11 TOTAL IMAGES--> 5
CLUSTER--> 12 TOTAL IMAGES--> 4
CLUSTER--> 13 TOTAL IMAGES--> 4
CLUSTER--> 14 TOTAL IMAGES--> 4
CLUSTER--> 15 TOTAL IMAGES--> 5
CLUSTER--> 16 TOTAL IMAGES--> 4
CLUSTER--> 17 TOTAL IMAGES--> 4
CLUSTER--> 18 TOTAL IMAGES--> 5
CLUSTER--> 19 TOTAL IMAGES--> 4
CLUSTER--> 20 TOTAL IMAGES--> 6
CLUSTER--> 21 TOTAL IMAGES--> 5
CLUSTER--> 22 TOTAL IMAGES--> 5
CLUSTER--> 23 TOTAL IMAGES--> 7
CLUSTER--> 24 TOTAL IMAGES--> 6
CLUSTER--> 25 TOTAL IMAGES--> 8
CLUSTER--> 26 TOTAL IMAGES--> 2
CLUSTER--> 27 TOTAL IMAGES--> 7
CLUSTER--> 28 TOTAL IMAGES--> 5
CLUSTER--> 29 TOTAL IMAGES--> 7
CLUSTER--> 30 TOTAL IMAGES--> 7
CLUSTER--> 31 TOTAL IMAGES--> 4
CLUSTER--> 32 TOTAL IMAGES--> 6
CLUSTER--> 33 TOTAL IMAGES--> 8
CLUSTER--> 34 TOTAL IMAGES--> 4
CLUSTER--> 35 TOTAL IMAGES--> 5
CLUSTER--> 36 TOTAL IMAGES--> 9
CLUSTER--> 37 TOTAL IMAGES--> 7
CLUSTER--> 38 TOTAL IMAGES--> 6
CLUSTER--> 39 TOTAL IMAGES--> 4
CLUSTER--> 40 TOTAL IMAGES--> 4
CLUSTER--> 41 TOTAL IMAGES--> 4
CLUSTER--> 42 TOTAL IMAGES--> 3
CLUSTER--> 43 TOTAL IMAGES--> 6
CLUSTER--> 44 TOTAL IMAGES--> 7
CLUSTER--> 45 TOTAL IMAGES--> 3
CLUSTER--> 46 TOTAL IMAGES--> 4
CLUSTER--> 47 TOTAL IMAGES--> 8
CLUSTER--> 48 TOTAL IMAGES--> 5
CLUSTER--> 49 TOTAL IMAGES--> 4
CLUSTER--> 50 TOTAL IMAGES--> 4
CLUSTER--> 51 TOTAL IMAGES--> 9
CLUSTER--> 52 TOTAL IMAGES--> 6
CLUSTER--> 53 TOTAL IMAGES--> 5
CLUSTER--> 54 TOTAL IMAGES--> 7
CLUSTER--> 55 TOTAL IMAGES--> 4
CLUSTER--> 56 TOTAL IMAGES--> 4
CLUSTER--> 57 TOTAL IMAGES--> 4
CLUSTER--> 58 TOTAL IMAGES--> 4
CLUSTER--> 59 TOTAL IMAGES--> 5
CLUSTER--> 60 TOTAL IMAGES--> 5
CLUSTER--> 61 TOTAL IMAGES--> 4
CLUSTER--> 62 TOTAL IMAGES--> 5
CLUSTER--> 63 TOTAL IMAGES--> 6
CLUSTER--> 64 TOTAL IMAGES--> 7
CLUSTER--> 65 TOTAL IMAGES--> 4
CLUSTER--> 66 TOTAL IMAGES--> 6
CLUSTER--> 67 TOTAL IMAGES--> 6
CLUSTER--> 68 TOTAL IMAGES--> 5
CLUSTER--> 69 TOTAL IMAGES--> 3
CLUSTER--> 70 TOTAL IMAGES--> 4
CLUSTER--> 71 TOTAL IMAGES--> 5
CLUSTER--> 72 TOTAL IMAGES--> 6
CLUSTER--> 73 TOTAL IMAGES--> 4
CLUSTER--> 74 TOTAL IMAGES--> 5
CLUSTER--> 75 TOTAL IMAGES--> 4
CLUSTER--> 76 TOTAL IMAGES--> 2
CLUSTER--> 77 TOTAL IMAGES--> 6
CLUSTER--> 78 TOTAL IMAGES--> 6
CLUSTER--> 79 TOTAL IMAGES--> 6
CLUSTER--> 80 TOTAL IMAGES--> 4
CLUSTER--> 81 TOTAL IMAGES--> 4
CLUSTER--> 82 TOTAL IMAGES--> 5
CLUSTER--> 83 TOTAL IMAGES--> 5
CLUSTER--> 84 TOTAL IMAGES--> 4
CLUSTER--> 85 TOTAL IMAGES--> 5
CLUSTER--> 86 TOTAL IMAGES--> 4
CLUSTER--> 87 TOTAL IMAGES--> 6
CLUSTER--> 88 TOTAL IMAGES--> 4
CLUSTER--> 89 TOTAL IMAGES--> 5
CLUSTER--> 90 TOTAL IMAGES--> 5
CLUSTER--> 91 TOTAL IMAGES--> 4
CLUSTER--> 92 TOTAL IMAGES--> 4
CLUSTER--> 93 TOTAL IMAGES--> 6
CLUSTER--> 94 TOTAL IMAGES--> 7
CLUSTER--> 95 TOTAL IMAGES--> 4
CLUSTER--> 96 TOTAL IMAGES--> 3
CLUSTER--> 97 TOTAL IMAGES--> 6
CLUSTER--> 98 TOTAL IMAGES--> 6
CLUSTER--> 99 TOTAL IMAGES--> 5
CLUSTER--> 100 TOTAL IMAGES--> 3
CLUSTER--> 101 TOTAL IMAGES--> 6
CLUSTER--> 102 TOTAL IMAGES--> 3
CLUSTER--> 103 TOTAL IMAGES--> 7
CLUSTER--> 104 TOTAL IMAGES--> 5
CLUSTER--> 105 TOTAL IMAGES--> 4
CLUSTER--> 106 TOTAL IMAGES--> 5
CLUSTER--> 107 TOTAL IMAGES--> 5
CLUSTER--> 108 TOTAL IMAGES--> 4
CLUSTER--> 109 TOTAL IMAGES--> 6
CLUSTER--> 110 TOTAL IMAGES--> 5
CLUSTER--> 111 TOTAL IMAGES--> 3
CLUSTER--> 112 TOTAL IMAGES--> 6
CLUSTER--> 113 TOTAL IMAGES--> 4
CLUSTER--> 114 TOTAL IMAGES--> 4
CLUSTER--> 115 TOTAL IMAGES--> 8
CLUSTER--> 116 TOTAL IMAGES--> 5
CLUSTER--> 117 TOTAL IMAGES--> 4
CLUSTER--> 118 TOTAL IMAGES--> 3
CLUSTER--> 119 TOTAL IMAGES--> 4
CLUSTER--> 120 TOTAL IMAGES--> 5
CLUSTER--> 121 TOTAL IMAGES--> 6
CLUSTER--> 122 TOTAL IMAGES--> 4
CLUSTER--> 123 TOTAL IMAGES--> 4
CLUSTER--> 124 TOTAL IMAGES--> 4
CLUSTER--> 125 TOTAL IMAGES--> 4
CLUSTER--> 126 TOTAL IMAGES--> 4
CLUSTER--> 127 TOTAL IMAGES--> 3
CLUSTER--> 128 TOTAL IMAGES--> 4
CLUSTER--> 129 TOTAL IMAGES--> 6
CLUSTER--> 130 TOTAL IMAGES--> 4
CLUSTER--> 131 TOTAL IMAGES--> 6
CLUSTER--> 132 TOTAL IMAGES--> 4
CLUSTER--> 133 TOTAL IMAGES--> 5
CLUSTER--> 134 TOTAL IMAGES--> 4
CLUSTER--> 135 TOTAL IMAGES--> 5
CLUSTER--> 136 TOTAL IMAGES--> 7
CLUSTER--> 137 TOTAL IMAGES--> 5
CLUSTER--> 138 TOTAL IMAGES--> 4
CLUSTER--> 139 TOTAL IMAGES--> 5
CLUSTER--> 140 TOTAL IMAGES--> 4
CLUSTER--> 141 TOTAL IMAGES--> 2
CLUSTER--> 142 TOTAL IMAGES--> 5
CLUSTER--> 143 TOTAL IMAGES--> 3
CLUSTER--> 144 TOTAL IMAGES--> 4
CLUSTER--> 145 TOTAL IMAGES--> 4
CLUSTER--> 146 TOTAL IMAGES--> 4
CLUSTER--> 147 TOTAL IMAGES--> 4
CLUSTER--> 148 TOTAL IMAGES--> 6
CLUSTER--> 149 TOTAL IMAGES--> 3
CLUSTER--> 150 TOTAL IMAGES--> 5
CLUSTER--> 151 TOTAL IMAGES--> 4
CLUSTER--> 152 TOTAL IMAGES--> 4
CLUSTER--> 153 TOTAL IMAGES--> 5
CLUSTER--> 154 TOTAL IMAGES--> 3
CLUSTER--> 155 TOTAL IMAGES--> 5
CLUSTER--> 156 TOTAL IMAGES--> 3
CLUSTER--> 157 TOTAL IMAGES--> 3
CLUSTER--> 158 TOTAL IMAGES--> 5
CLUSTER--> 159 TOTAL IMAGES--> 4
CLUSTER--> 160 TOTAL IMAGES--> 4
CLUSTER--> 161 TOTAL IMAGES--> 4
CLUSTER--> 162 TOTAL IMAGES--> 5
CLUSTER--> 163 TOTAL IMAGES--> 4
CLUSTER--> 164 TOTAL IMAGES--> 5
CLUSTER--> 165 TOTAL IMAGES--> 3
CLUSTER--> 166 TOTAL IMAGES--> 4
CLUSTER--> 167 TOTAL IMAGES--> 3
CLUSTER--> 168 TOTAL IMAGES--> 5
CLUSTER--> 169 TOTAL IMAGES--> 4
CLUSTER--> 170 TOTAL IMAGES--> 5
CLUSTER--> 171 TOTAL IMAGES--> 3
CLUSTER--> 172 TOTAL IMAGES--> 3
CLUSTER--> 173 TOTAL IMAGES--> 2
CLUSTER--> 174 TOTAL IMAGES--> 5
CLUSTER--> 175 TOTAL IMAGES--> 4
CLUSTER--> 176 TOTAL IMAGES--> 3
CLUSTER--> 177 TOTAL IMAGES--> 4
CLUSTER--> 178 TOTAL IMAGES--> 4
CLUSTER--> 179 TOTAL IMAGES--> 6
CLUSTER--> 180 TOTAL IMAGES--> 3
CLUSTER--> 181 TOTAL IMAGES--> 8
CLUSTER--> 182 TOTAL IMAGES--> 6
CLUSTER--> 183 TOTAL IMAGES--> 4
CLUSTER--> 184 TOTAL IMAGES--> 4
CLUSTER--> 185 TOTAL IMAGES--> 5
CLUSTER--> 186 TOTAL IMAGES--> 5
CLUSTER--> 187 TOTAL IMAGES--> 5
CLUSTER--> 188 TOTAL IMAGES--> 8
CLUSTER--> 189 TOTAL IMAGES--> 4
CLUSTER--> 190 TOTAL IMAGES--> 4
CLUSTER--> 191 TOTAL IMAGES--> 4
CLUSTER--> 192 TOTAL IMAGES--> 3
CLUSTER--> 193 TOTAL IMAGES--> 3
CLUSTER--> 194 TOTAL IMAGES--> 5
CLUSTER--> 195 TOTAL IMAGES--> 5
CLUSTER--> 196 TOTAL IMAGES--> 3
CLUSTER--> 197 TOTAL IMAGES--> 4
CLUSTER--> 198 TOTAL IMAGES--> 4
CLUSTER--> 199 TOTAL IMAGES--> 5
CLUSTER--> 200 TOTAL IMAGES--> 4
CLUSTER--> 201 TOTAL IMAGES--> 4
CLUSTER--> 202 TOTAL IMAGES--> 4
CLUSTER--> 203 TOTAL IMAGES--> 4
CLUSTER--> 204 TOTAL IMAGES--> 4
CLUSTER--> 205 TOTAL IMAGES--> 4
CLUSTER--> 206 TOTAL IMAGES--> 5
CLUSTER--> 207 TOTAL IMAGES--> 4
CLUSTER--> 208 TOTAL IMAGES--> 3
CLUSTER--> 209 TOTAL IMAGES--> 4
CLUSTER--> 210 TOTAL IMAGES--> 4
CLUSTER--> 211 TOTAL IMAGES--> 7
CLUSTER--> 212 TOTAL IMAGES--> 6
CLUSTER--> 213 TOTAL IMAGES--> 4
CLUSTER--> 214 TOTAL IMAGES--> 8
CLUSTER--> 215 TOTAL IMAGES--> 2
CLUSTER--> 216 TOTAL IMAGES--> 6
CLUSTER--> 217 TOTAL IMAGES--> 5
CLUSTER--> 218 TOTAL IMAGES--> 4
CLUSTER--> 219 TOTAL IMAGES--> 5
CLUSTER--> 220 TOTAL IMAGES--> 3
CLUSTER--> 221 TOTAL IMAGES--> 5
CLUSTER--> 222 TOTAL IMAGES--> 3
CLUSTER--> 223 TOTAL IMAGES--> 5
CLUSTER--> 224 TOTAL IMAGES--> 3
CLUSTER--> 225 TOTAL IMAGES--> 4
CLUSTER--> 226 TOTAL IMAGES--> 7
CLUSTER--> 227 TOTAL IMAGES--> 8
CLUSTER--> 228 TOTAL IMAGES--> 6
CLUSTER--> 229 TOTAL IMAGES--> 5
CLUSTER--> 230 TOTAL IMAGES--> 3
CLUSTER--> 231 TOTAL IMAGES--> 4
CLUSTER--> 232 TOTAL IMAGES--> 3
CLUSTER--> 233 TOTAL IMAGES--> 5
CLUSTER--> 234 TOTAL IMAGES--> 3
CLUSTER--> 235 TOTAL IMAGES--> 4
CLUSTER--> 236 TOTAL IMAGES--> 2
CLUSTER--> 237 TOTAL IMAGES--> 8
CLUSTER--> 238 TOTAL IMAGES--> 4
CLUSTER--> 239 TOTAL IMAGES--> 4
CLUSTER--> 240 TOTAL IMAGES--> 3
CLUSTER--> 241 TOTAL IMAGES--> 5
CLUSTER--> 242 TOTAL IMAGES--> 7
CLUSTER--> 243 TOTAL IMAGES--> 4
CLUSTER--> 244 TOTAL IMAGES--> 3
CLUSTER--> 245 TOTAL IMAGES--> 4
CLUSTER--> 246 TOTAL IMAGES--> 5
CLUSTER--> 247 TOTAL IMAGES--> 5
CLUSTER--> 248 TOTAL IMAGES--> 4
CLUSTER--> 249 TOTAL IMAGES--> 2
CLUSTER--> 250 TOTAL IMAGES--> 3
CLUSTER--> 251 TOTAL IMAGES--> 3
CLUSTER--> 252 TOTAL IMAGES--> 3
CLUSTER--> 253 TOTAL IMAGES--> 3
CLUSTER--> 254 TOTAL IMAGES--> 5
CLUSTER--> 255 TOTAL IMAGES--> 3
CLUSTER--> 256 TOTAL IMAGES--> 3
CLUSTER--> 257 TOTAL IMAGES--> 4
CLUSTER--> 258 TOTAL IMAGES--> 5
CLUSTER--> 259 TOTAL IMAGES--> 4
CLUSTER--> 260 TOTAL IMAGES--> 4
predicted_Labels=np.load('image-results-hier/ideology_model_resnet50.npy-tsne_birch_labels.npy')
unique_labels=set(predicted_Labels)
for label in unique_labels:
if(label!=-1):
showClustering(predicted_Labels,label)