Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 9eec0a39 authored by Hachemin Pierre-Yves's avatar Hachemin Pierre-Yves

Cluster and data vis

parent 4146b653
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# import the necessary packages\n",
"from sklearn.cluster import KMeans\n",
"import matplotlib.pyplot as plt\n",
"import argparse\n",
"import numpy as np\n",
"import cv2"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def centroid_histogram(clt):\n",
"\t# grab the number of different clusters and create a histogram\n",
"\t# based on the number of pixels assigned to each cluster\n",
"\tnumLabels = np.arange(0, len(np.unique(clt.labels_)) + 1)\n",
"\t(hist, _) = np.histogram(clt.labels_, bins = numLabels)\n",
" \n",
"\t# normalize the histogram, such that it sums to one\n",
"\thist = hist.astype(\"float\")\n",
"\thist /= hist.sum()\n",
" \n",
"\t# return the histogram\n",
"\treturn hist\n",
"\n",
"def plot_colors(hist, centroids):\n",
"\t# initialize the bar chart representing the relative frequency\n",
"\t# of each of the colors\n",
"\tbar = np.zeros((50, 300, 3), dtype = \"uint8\")\n",
"\tstartX = 0\n",
" \n",
"\t# loop over the percentage of each cluster and the color of\n",
"\t# each cluster\n",
"\tfor (percent, color) in zip(hist, centroids):\n",
"\t\t# plot the relative percentage of each cluster\n",
"\t\tendX = startX + (percent * 300)\n",
"\t\tcv2.rectangle(bar, (int(startX), 0), (int(endX), 50),\n",
"\t\t\tcolor.astype(\"uint8\").tolist(), -1)\n",
"\t\tstartX = endX\n",
"\t\n",
"\t# return the bar chart\n",
"\treturn bar"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"def cluster(path,nb_clusters,legend):\n",
" # load the image and convert it from BGR to LAB so that\n",
" # we can dispaly it with matplotlib\n",
" image = cv2.imread(path,1)\n",
" image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n",
"\n",
" # show our image\n",
" print(legend)\n",
" plt.figure()\n",
" plt.axis(\"off\")\n",
" plt.imshow(image)\n",
"\n",
"\n",
" # reshape the image to be a list of pixels\n",
" image = image.reshape((image.shape[0] * image.shape[1], 3))\n",
"\n",
" # cluster the pixel intensities\n",
" clt = KMeans(n_clusters = nb_clusters)\n",
" clt.fit(image)\n",
" # build a histogram of clusters and then create a figure\n",
" # representing the number of pixels labeled to each color\n",
" hist = centroid_histogram(clt)\n",
" print(hist)\n",
" bar = plot_colors(hist, clt.cluster_centers_)\n",
"\n",
" # show our color bart\n",
" plt.figure()\n",
" plt.axis(\"off\")\n",
" plt.imshow(bar)\n",
" plt.show()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trailer\n",
"[0.15502183 0.00655022 0.0720524 0.1069869 0.05021834 0.10043668\n",
" 0.09606987 0.18122271 0.22489083 0.00655022]\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAABhCAYAAADGD1rPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAABW9JREFUeJzt3E2rHmcZwPH/dc88zzlPzjlNTvNqa4umTSAtVEtxIYguSutCcCvoV/CDKPgJFD+Fq1QJDZaiC0WtupCkbWqStjZtzvt5Xmbu28UJFUF3xeLF/7eaxTBzzcXwZ1YTrTUkSf//yuc9gCTps2HQJSkJgy5JSRh0SUrCoEtSEgZdkpIw6JKUhEGXpCQMuiQlYdAlKYn+f3mz2ZlZu7C9xcak57FZz6XTp9iardPFfz4/Dj/89LgLaG3kmctP08dAtEoloBVaFIIlrQV1hK7AUFdEBH+/v0ujo0ajtR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RBl6QkDLokJWHQJSkJgy5JSRh0SUrCoEtSEgZdkpIw6JKUhEGXpCQMuiQlYdAlKQmDLklJGHRJSsKgS1ISBl2SkjDokpSEQZekJAy6JCVh0CUpCYMuSUkYdElKwqBLUhIGXZKSMOiSlIRBl6QkDLokJWHQJSkJgy5JSRh0SUrCoEtSEgZdkpIw6JKUhEGXpCQMuiQlYdAlKQmDLklJGHRJSsKgS1ISBl2SkjDokpSEQZekJAy6JCVh0CUpCYMuSUkYdElKwqBLUhIGXZKSMOiSlIRBl6QkDLokJWHQJSkJgy5JSRh0SUoiWmuf9wySpM+AX+iSlIRBl6QkDLokJWHQJSkJgy5JSRh0SUrCoEtSEgZdkpIw6JKUhEGXpCQMuiQlYdAlKQmDLklJGHRJSsKgS1ISBl2SkjDokpSEQZekJAy6JCVh0CUpCYMuSUkYdElKwqBLUhL/BJnjuczbAJ7+AAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x229bc62c630>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAABaCAYAAACosq2hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAAc5JREFUeJzt261NBFEARtFZQgkYVqzGkNAANdABRWAIDoNBE2rA0AAFkGAxCDxZjSQhg0ND9meyN+eoEZP3PnUzZmbjOA4A7L69qQcAsB6CDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AAR+9u87PRkkfkt9fbq4vf56eV1o3fdPzxu9Pz/Oju/XvmMz+X76kNWdPz9PPWE4e3ja+oJW3Uwn089Yadc3twNwzAMh4uj2V/e94UOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOEDEbx3HqDQCsgS90gAhBB4gQdIAIQQeIEHSACEEHiBB0gAhBB4gQdIAIQQeIEHSACEEHiBB0gAhBB4gQdIAIQQeIEHSACEEHiBB0gAhBB4gQdIAIQQeIEHSAiB8zeRivxgpvXAAAAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x229bb5bc6a0>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Movie\n",
"[0.1197408 0.04578541 0.10460296 0.07314498 0.12567704 0.06725622\n",
" 0.10688443 0.04758595 0.17575186 0.13357035]\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXsAAABiCAYAAACxkHPsAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAC0JJREFUeJzt3M+Pndddx/H395zzPPfeuTPjscfjTJo40Dg/SNNikpZQCBAoUquKPV0gNrACwYoFLJAQCIGQ+gdUCLFgG6TuEEJIFEFRq8RKQ1Eb1KRx4sSO7Thjz4zvnXuf55wvi+eOf3RVFlEizuclPfJ45s55nuec87x9PYsxd0dERP5/Cx/1BYiIyIdPsRcRqYBiLyJSAcVeRKQCir2ISAUUexGRCij2IiIVUOxFRCqg2IuIVECxFxGpQPqoLwDgJ5/7Vf+NZx/h7GMP8cd/8lc898Qj/PTjDWdP7PLyDy5RyoifeWqL7Y01JrzDm5cmvHblkKvzxEbK3JgEPrhyhecfSnz61Ij9Zkq3aLGjQ1763mUmOz/B+ad3KHHCu5cvM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Yi4hUQLEXEamAYi8iUgHFXkSkAoq9iEgFFHsRkQoo9iIiFVDsRUQqoNiLiFTA3P2jvgYREfmQ6Z29iEgFFHsRkQoo9iIiFVDsRUQqoNiLiFRAsRcRqYBiLyJSAcVeRKQCir2ISAUUexGRCij2IiIVUOxFRCqg2IuIVECxFxGpgGIvIlIBxV5EpAKKvYhIBRR7EZEKKPYiIhVQ7EVEKqDYi4hUQLEXEamAYi8iUoH/BTUBw9CBYH3lAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x22996b3fba8>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAABaCAYAAACosq2hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAAcxJREFUeJzt27ExBVEUgGHPqEAqpAszIiN5idTIBCIdiJWgAJkSBFRgJBIiM5SggdUCdtd7/vm++N6zJ/rnJrsYhmEDgP9vc9ULADANQQeIEHSACEEHiBB0gAhBB4gQdIAIQQeIEHSAiK2//Nj54e7a/pZ6dHoy6v7l1c1Em4y3f3w26/zPl4dZ509lb3kx2+zt97vZZv/UzsFy9Izn2+sJNll/T68fq17hV+4f3xbfOeeFDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhAh6AARgg4QIegAEYIOECHoABGCDhCxGIZh1TsAMAEvdIAIQQeIEHSACEEHiBB0gAhBB4gQdIAIQQeIEHSACEEHiBB0gAhBB4gQdIAIQQeIEHSACEEHiBB0gAhBB4gQdIAIQQeIEHSACEEHiBB0gIgvwzgYr8HCLXIAAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x229bc62c828>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"path_movie=\"./spectrumImages/spectrumImagesAsterix/7plagklTwWw.jpg\"\n",
"path_trailer=\"./spectrumImages/spectrumImagesAsterix/DR1a7R5usts.jpg\"\n",
"nb_clusters=10\n",
"\n",
"cluster(path_trailer,nb_clusters,'Trailer')\n",
"cluster(path_movie,nb_clusters, 'Movie')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
import ast
import os
import cv2
import requests
import matplotlib.pyplot as plt
#L = ['Sithad108Og.','fBNpSRtfIUA', '2e-eXJ6HgkQ', 'tN1A2mVnrOM', 'myTaigPrbsg', 'b75lZw8nkvo']
genres = [28, 35, 18, 99, 10749, 10752, 10402, 53, 878, 27, 9648, 80, 14, 12, 36, 10769, 16, 10751, 37, 10770]
list_of_eligible_spectrums = []
for file in os.listdir("SpectrumImages2005"):
if str(file)[-4:] == '.jpg':
list_of_eligible_spectrums += [file]
print(len(list_of_eligible_spectrums))
# def get_genre_from_link():
# path = "./Link-dictionaries/Link-dictionary2005.txt"
# file = open(path, "r").read()
# dictyear = ast.literal_eval(file)
# dict_inverse = {}
# links_to_be_removed = []
# for movie_id in dictyear.keys():
# if dictyear[movie_id][1] != []:
# dict_inverse[str(dictyear[movie_id][2])] = {}
# for genre in genres:
# if genre in dictyear[movie_id][1]:
# dict_inverse[str(dictyear[movie_id][2])][genre] = 1
# else:
# dict_inverse[str(dictyear[movie_id][2])][genre] = 0
# else:
# #print(f'careful, link {dictyear[movie_id][2]} needs to be removed from the list')
# links_to_be_removed += [dictyear[movie_id][2]]
# return dict_inverse, links_to_be_removed
#
#
# def get_output_list(L):
# dict_inverse, links_to_be_removed = get_genre_from_link()
# eligible_links = []
# output = []
# for link in L:
# link = str(link)
# #print(dict_inverse[str(link)])
# if link[-1] == ".":
# print("do something! Too many points.......")
# if link[:-4] not in links_to_be_removed:
# output += [dict_inverse[link[:-4]]]
# eligible_links += [link]
# return output, eligible_links
# labels, eligible_links = get_output_list(list_of_eligible_spectrums)
def get_genre_from_link():
path = "./Link-dictionaries/Link-dictionary2005.txt"
file = open(path, "r").read()
dictyear = ast.literal_eval(file)
dict_inverse = {}
links_to_be_removed = []
for movie_id in dictyear.keys():
if dictyear[movie_id][1] != []:
dict_inverse[str(dictyear[movie_id][2])] = {}
for genre in genres:
if genre in dictyear[movie_id][1]:
dict_inverse[str(dictyear[movie_id][2])][genre] = 1
else:
dict_inverse[str(dictyear[movie_id][2])][genre] = 0
else:
#print(f'careful, link {dictyear[movie_id][2]} needs to be removed from the list')
links_to_be_removed += [dictyear[movie_id][2]]
return dict_inverse, links_to_be_removed
years = range(2000, 2018)
def get_output_list(L):
dict_inverse, links_to_be_removed = get_genre_from_link()
eligible_links = []
output = []
for link in L:
link = str(link)
#print(dict_inverse[str(link)])
if link[-1] == ".":
print("do something! Too many points.......")
if link[:-4] not in links_to_be_removed:
eligible_links += [link[:-4]]
return dict_inverse, eligible_links
dict_inverse, eligible_links = get_output_list(list_of_eligible_spectrums)
for file in eligible_links:
img = cv2.imread('SpectrumImages2005/' + file + '.jpg', 1)
img = img[0:1]
img = img.reshape((img.shape[1], img.shape[2]))
dict_inverse[file]['image'] += [img]
print('coucocu')
list_of_eligible_spectrums = []
for year in years:
for file in os.listdir("./spectrumImages/SpectrumImages" + str(year)):
if str(file)[-4:] == '.jpg':
list_of_eligible_spectrums += ['SpectrumImages'+ str(year) +'/' + file]
url = "https://api.themoviedb.org/3/genre/movie/list?"
API = 'api_key=a9075982d1f7ce05cc45adec0e5f5358&language=en-US'
......@@ -128,21 +48,12 @@ def sum_genre(list_years):
final_dict_genre[key] = dict_genre[key]
return final_dict_genre
sum_genre = sum_genre(range(2000, 2018))
# print(get_genres(2001).keys())
# #print(get_genres(2002).keys())
# print(get_genres(2003).keys())
# print(get_genres(2004).keys())
# print(get_genres(2005).keys())
#print(translate_genre())
sum_genre = sum_genre(range(2003, 2014))
L = []
for key in sum_genre.keys():
L += [str(key)]
print(L, list(sum_genre.values()))
print(sum(list(sum_genre.values())))
plt.bar(L, list(sum_genre.values()))
plt.show()
plt.show()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment