Пример #1
0
def plot_mosaics(config, clustering_type, clustering, output_image_width,
                 output_image_height, mosaic_nrow, mosaic_ncol_max):
    """
    Mosaic of each cluster
    """
    clusters_id = np.unique(clustering.final_labels)
    clustering_res = clustering.get_results()

    for cluster_id in clusters_id:
        cluster_image_filenames = [
            os.path.join(
                config.get('directory')['collections'], "%s.jpg" % one_res[0])
            for one_res in clustering_res if one_res[1] == cluster_id
        ]

        images_array = [
            Tools.read_np_picture(img_filename,
                                  target_size=(output_image_height,
                                               output_image_width))
            for img_filename in cluster_image_filenames
        ]

        img = Tools.display_mosaic(images_array,
                                   nrow=mosaic_nrow,
                                   ncol_max=mosaic_ncol_max)
        img.save(
            os.path.join(clustering.save_directory,
                         "cluster_%s.png" % str(cluster_id).zfill(2)), "PNG")

    return clusters_id
    res_tmp = select_cluster(clustering, cl)
    print(len(res_tmp))
    image_array = [Tools.read_np_picture(f, target_size = (54, 96)) for f in res_tmp[:100]]
    # img = Tools.display_mosaic(image_array, nrow = 10)
    # fig = plt.figure(1, figsize=(12, 7))
    # plt.imshow(img, aspect = 'auto')
    # plt.show()


#%% [markdown]
# ## Zoom sur le cluster 0

#%%
res_tmp = select_cluster(clustering, 1)

#%%
print(len(res_tmp))
image_array = [Tools.read_np_picture(f, target_size = (54, 96)) for f in res_tmp]


#%%
Tools.display_mosaic(image_array, nrow = 18)


#%%
col = [1 if l == 1 else 0 for l in clustering.kmeans_labels]
plt.scatter(clustering.pca_reduction[:, 0], clustering.pca_reduction[:, 1], c = col)

#%%
plt.scatter(clustering.pca_reduction[np.array(col) == 1, 0], clustering.pca_reduction[np.array(col) == 1, 1])
Пример #3
0
#%%[markdown]
# # Graphiques

#%%
def select_cluster(clustering, id_cluster):
    return [os.path.join('data/processed/models/autoencoder/train/k/', res[0] + '.jpg') for res in clustering.get_zip_results() if res[2] == id_cluster]


#%%
for cl in np.unique(clustering.kmeans_labels):
    print("Cluster %s" % (cl))
    res_tmp = select_cluster(clustering, cl)
    if len(res_tmp) >= 0:
        print(len(res_tmp))
        image_array = [Tools.read_np_picture(f, target_size = (54, 96)) for f in res_tmp[:100]]
        img = Tools.display_mosaic(image_array, nrow = 10)
        fig = plt.figure(1, figsize=(12, 7))
        plt.imshow(img, aspect = 'auto')
        plt.show()

#%% [markdown]
# ## faut essayer de faire des paquets

#%%
from sklearn.manifold import TSNE

output_tnse = TSNE(n_components=2).fit_transform(clustering.pca_reduction)


#%%
plt.scatter(