In [4]:
import pandas as pd
import numpy as np
from collections import Counter
from matplotlib import pyplot as plt
import os
import cv2
%matplotlib inline
In [5]:
%%javascript
IPython.OutputArea.auto_scroll_threshold = 9999;
In [6]:
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()
In [7]:
results_df=pd.read_csv('image-results-hier/ideology_model_vgg_19.npy-tsne.csv')
results_df
Out[7]:
Unnamed: 0 n_clusters silhouette calinski davies
0 Birch 1220 0.342789 744.985427 0.594890
1 Agglomerative clustering 906 0.429054 832.622970 0.661691
In [ ]:
predicted_Labels=np.load('image-results-hier/ideology_model_vgg_19.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-->  5
CLUSTER-->  1 TOTAL IMAGES-->  7
CLUSTER-->  2 TOTAL IMAGES-->  5
CLUSTER-->  3 TOTAL IMAGES-->  5
CLUSTER-->  4 TOTAL IMAGES-->  6
CLUSTER-->  5 TOTAL IMAGES-->  6
CLUSTER-->  6 TOTAL IMAGES-->  4
CLUSTER-->  7 TOTAL IMAGES-->  4
CLUSTER-->  8 TOTAL IMAGES-->  6
CLUSTER-->  9 TOTAL IMAGES-->  6
CLUSTER-->  10 TOTAL IMAGES-->  5
CLUSTER-->  11 TOTAL IMAGES-->  4
CLUSTER-->  12 TOTAL IMAGES-->  5
CLUSTER-->  13 TOTAL IMAGES-->  2
CLUSTER-->  14 TOTAL IMAGES-->  4
CLUSTER-->  15 TOTAL IMAGES-->  4
CLUSTER-->  16 TOTAL IMAGES-->  6
CLUSTER-->  17 TOTAL IMAGES-->  5
CLUSTER-->  18 TOTAL IMAGES-->  7
CLUSTER-->  19 TOTAL IMAGES-->  6
CLUSTER-->  20 TOTAL IMAGES-->  8
CLUSTER-->  21 TOTAL IMAGES-->  3
CLUSTER-->  22 TOTAL IMAGES-->  4
CLUSTER-->  23 TOTAL IMAGES-->  6
CLUSTER-->  24 TOTAL IMAGES-->  6
CLUSTER-->  25 TOTAL IMAGES-->  4
CLUSTER-->  26 TOTAL IMAGES-->  4
CLUSTER-->  27 TOTAL IMAGES-->  6
CLUSTER-->  28 TOTAL IMAGES-->  5
CLUSTER-->  29 TOTAL IMAGES-->  8
CLUSTER-->  30 TOTAL IMAGES-->  5
CLUSTER-->  31 TOTAL IMAGES-->  4
CLUSTER-->  32 TOTAL IMAGES-->  6
CLUSTER-->  33 TOTAL IMAGES-->  4
CLUSTER-->  34 TOTAL IMAGES-->  4
CLUSTER-->  35 TOTAL IMAGES-->  6
CLUSTER-->  36 TOTAL IMAGES-->  7
CLUSTER-->  37 TOTAL IMAGES-->  3
CLUSTER-->  38 TOTAL IMAGES-->  4
CLUSTER-->  39 TOTAL IMAGES-->  5
CLUSTER-->  40 TOTAL IMAGES-->  4
CLUSTER-->  41 TOTAL IMAGES-->  4
CLUSTER-->  42 TOTAL IMAGES-->  2
CLUSTER-->  43 TOTAL IMAGES-->  5
CLUSTER-->  44 TOTAL IMAGES-->  6
CLUSTER-->  45 TOTAL IMAGES-->  5
CLUSTER-->  46 TOTAL IMAGES-->  2
CLUSTER-->  47 TOTAL IMAGES-->  6
CLUSTER-->  48 TOTAL IMAGES-->  4
CLUSTER-->  49 TOTAL IMAGES-->  8
CLUSTER-->  50 TOTAL IMAGES-->  5
CLUSTER-->  51 TOTAL IMAGES-->  5
CLUSTER-->  52 TOTAL IMAGES-->  4
CLUSTER-->  53 TOTAL IMAGES-->  8
CLUSTER-->  54 TOTAL IMAGES-->  4
CLUSTER-->  55 TOTAL IMAGES-->  3
CLUSTER-->  56 TOTAL IMAGES-->  2
CLUSTER-->  57 TOTAL IMAGES-->  3
CLUSTER-->  58 TOTAL IMAGES-->  4
CLUSTER-->  59 TOTAL IMAGES-->  3
CLUSTER-->  60 TOTAL IMAGES-->  6
CLUSTER-->  61 TOTAL IMAGES-->  6
CLUSTER-->  62 TOTAL IMAGES-->  5
CLUSTER-->  63 TOTAL IMAGES-->  7
CLUSTER-->  64 TOTAL IMAGES-->  4
CLUSTER-->  65 TOTAL IMAGES-->  5
CLUSTER-->  66 TOTAL IMAGES-->  5
CLUSTER-->  67 TOTAL IMAGES-->  6
CLUSTER-->  68 TOTAL IMAGES-->  5
CLUSTER-->  69 TOTAL IMAGES-->  4
CLUSTER-->  70 TOTAL IMAGES-->  3
CLUSTER-->  71 TOTAL IMAGES-->  7
CLUSTER-->  72 TOTAL IMAGES-->  5
CLUSTER-->  73 TOTAL IMAGES-->  4
CLUSTER-->  74 TOTAL IMAGES-->  3
CLUSTER-->  75 TOTAL IMAGES-->  4
CLUSTER-->  76 TOTAL IMAGES-->  4
CLUSTER-->  77 TOTAL IMAGES-->  3
CLUSTER-->  78 TOTAL IMAGES-->  4
CLUSTER-->  79 TOTAL IMAGES-->  5
CLUSTER-->  80 TOTAL IMAGES-->  4
CLUSTER-->  81 TOTAL IMAGES-->  4
CLUSTER-->  82 TOTAL IMAGES-->  5
CLUSTER-->  83 TOTAL IMAGES-->  2
CLUSTER-->  84 TOTAL IMAGES-->  4
CLUSTER-->  85 TOTAL IMAGES-->  5
CLUSTER-->  86 TOTAL IMAGES-->  6
CLUSTER-->  87 TOTAL IMAGES-->  5
CLUSTER-->  88 TOTAL IMAGES-->  5
CLUSTER-->  89 TOTAL IMAGES-->  5
CLUSTER-->  90 TOTAL IMAGES-->  4
CLUSTER-->  91 TOTAL IMAGES-->  6
CLUSTER-->  92 TOTAL IMAGES-->  4
CLUSTER-->  93 TOTAL IMAGES-->  8
CLUSTER-->  94 TOTAL IMAGES-->  4
CLUSTER-->  95 TOTAL IMAGES-->  5
CLUSTER-->  96 TOTAL IMAGES-->  4
CLUSTER-->  97 TOTAL IMAGES-->  4
CLUSTER-->  98 TOTAL IMAGES-->  8
CLUSTER-->  99 TOTAL IMAGES-->  5
CLUSTER-->  100 TOTAL IMAGES-->  6
CLUSTER-->  101 TOTAL IMAGES-->  4
CLUSTER-->  102 TOTAL IMAGES-->  2
CLUSTER-->  103 TOTAL IMAGES-->  4
CLUSTER-->  104 TOTAL IMAGES-->  5
CLUSTER-->  105 TOTAL IMAGES-->  3
CLUSTER-->  106 TOTAL IMAGES-->  6
CLUSTER-->  107 TOTAL IMAGES-->  4
CLUSTER-->  108 TOTAL IMAGES-->  3
CLUSTER-->  109 TOTAL IMAGES-->  4
CLUSTER-->  110 TOTAL IMAGES-->  4
CLUSTER-->  111 TOTAL IMAGES-->  6
CLUSTER-->  112 TOTAL IMAGES-->  3
CLUSTER-->  113 TOTAL IMAGES-->  6
CLUSTER-->  114 TOTAL IMAGES-->  4
CLUSTER-->  115 TOTAL IMAGES-->  2
CLUSTER-->  116 TOTAL IMAGES-->  7
CLUSTER-->  117 TOTAL IMAGES-->  4
CLUSTER-->  118 TOTAL IMAGES-->  4
CLUSTER-->  119 TOTAL IMAGES-->  3
CLUSTER-->  120 TOTAL IMAGES-->  4
CLUSTER-->  121 TOTAL IMAGES-->  4
CLUSTER-->  122 TOTAL IMAGES-->  3
CLUSTER-->  123 TOTAL IMAGES-->  4
CLUSTER-->  124 TOTAL IMAGES-->  4
CLUSTER-->  125 TOTAL IMAGES-->  4
CLUSTER-->  126 TOTAL IMAGES-->  6
CLUSTER-->  127 TOTAL IMAGES-->  3
CLUSTER-->  128 TOTAL IMAGES-->  2
CLUSTER-->  129 TOTAL IMAGES-->  6
CLUSTER-->  130 TOTAL IMAGES-->  3
CLUSTER-->  131 TOTAL IMAGES-->  3
CLUSTER-->  132 TOTAL IMAGES-->  4
CLUSTER-->  133 TOTAL IMAGES-->  3
CLUSTER-->  134 TOTAL IMAGES-->  7
CLUSTER-->  135 TOTAL IMAGES-->  5
CLUSTER-->  136 TOTAL IMAGES-->  4
CLUSTER-->  137 TOTAL IMAGES-->  4
CLUSTER-->  138 TOTAL IMAGES-->  5
CLUSTER-->  139 TOTAL IMAGES-->  3
CLUSTER-->  140 TOTAL IMAGES-->  4
CLUSTER-->  141 TOTAL IMAGES-->  4
CLUSTER-->  142 TOTAL IMAGES-->  4
CLUSTER-->  143 TOTAL IMAGES-->  10
CLUSTER-->  144 TOTAL IMAGES-->  3
CLUSTER-->  145 TOTAL IMAGES-->  6
CLUSTER-->  146 TOTAL IMAGES-->  3
CLUSTER-->  147 TOTAL IMAGES-->  7
CLUSTER-->  148 TOTAL IMAGES-->  4
CLUSTER-->  149 TOTAL IMAGES-->  4
CLUSTER-->  150 TOTAL IMAGES-->  4
CLUSTER-->  151 TOTAL IMAGES-->  3
CLUSTER-->  152 TOTAL IMAGES-->  3
CLUSTER-->  153 TOTAL IMAGES-->  4
CLUSTER-->  154 TOTAL IMAGES-->  3
CLUSTER-->  155 TOTAL IMAGES-->  6
CLUSTER-->  156 TOTAL IMAGES-->  5
CLUSTER-->  157 TOTAL IMAGES-->  4
CLUSTER-->  158 TOTAL IMAGES-->  4
CLUSTER-->  159 TOTAL IMAGES-->  5
CLUSTER-->  160 TOTAL IMAGES-->  4
CLUSTER-->  161 TOTAL IMAGES-->  4
CLUSTER-->  162 TOTAL IMAGES-->  4
CLUSTER-->  163 TOTAL IMAGES-->  7
CLUSTER-->  164 TOTAL IMAGES-->  4
CLUSTER-->  165 TOTAL IMAGES-->  3
CLUSTER-->  166 TOTAL IMAGES-->  5
CLUSTER-->  167 TOTAL IMAGES-->  4
CLUSTER-->  168 TOTAL IMAGES-->  4
CLUSTER-->  169 TOTAL IMAGES-->  5
CLUSTER-->  170 TOTAL IMAGES-->  3
CLUSTER-->  171 TOTAL IMAGES-->  3
CLUSTER-->  172 TOTAL IMAGES-->  3
CLUSTER-->  173 TOTAL IMAGES-->  3
CLUSTER-->  174 TOTAL IMAGES-->  2
CLUSTER-->  175 TOTAL IMAGES-->  4
CLUSTER-->  176 TOTAL IMAGES-->  4
CLUSTER-->  177 TOTAL IMAGES-->  5
CLUSTER-->  178 TOTAL IMAGES-->  2
CLUSTER-->  179 TOTAL IMAGES-->  7
CLUSTER-->  180 TOTAL IMAGES-->  2
CLUSTER-->  181 TOTAL IMAGES-->  3
CLUSTER-->  182 TOTAL IMAGES-->  3
CLUSTER-->  183 TOTAL IMAGES-->  4
CLUSTER-->  184 TOTAL IMAGES-->  4
CLUSTER-->  185 TOTAL IMAGES-->  5
CLUSTER-->  186 TOTAL IMAGES-->  3
CLUSTER-->  187 TOTAL IMAGES-->  4
CLUSTER-->  188 TOTAL IMAGES-->  5
CLUSTER-->  189 TOTAL IMAGES-->  3
CLUSTER-->  190 TOTAL IMAGES-->  5
CLUSTER-->  191 TOTAL IMAGES-->  4
CLUSTER-->  192 TOTAL IMAGES-->  4
CLUSTER-->  193 TOTAL IMAGES-->  3
CLUSTER-->  194 TOTAL IMAGES-->  2
CLUSTER-->  195 TOTAL IMAGES-->  3
CLUSTER-->  196 TOTAL IMAGES-->  5
CLUSTER-->  197 TOTAL IMAGES-->  4
In [ ]:
predicted_Labels=np.load('image-results-hier/ideology_model_vgg_19.npy-tsne_birch_labels.npy')
unique_labels=set(predicted_Labels)
for label in unique_labels:
    if(label!=-1):
        showClustering(predicted_Labels,label)