Skip to content
Snippets Groups Projects
Select Git revision
  • 7f47ef4fc72b0fdde03cb02606ad17f2d5a8a59a
  • master default
  • dockerization
  • staging
  • backup-before-cleaning-repo
  • dockerfiles-pour-maelle
6 results

objectifs.controller.js

Blame
  • Forked from an inaccessible project.
    loadFer2013ds.py 1.26 KiB
    #This file load the dataset fer2013 as arrays. 
    import csv
    import numpy as np
    import cv2
    import matplotlib.pyplot as plt
    
    
    nbrImages = 35887
    maxNbrImages = nbrImages
    emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"]
    
    def traitement(a,b,c):  #For testing
    	pass
    	# arr = strToArray(b)
    	# print(a)
    	# plt.imshow(arr)
    	# plt.show()
    	# pass
    
    def strToArray(string):  #Fer2013 provides images as string so it needs to be transformed
    	A = []
    	lenght = len(string)
    	i=0
    	nbr = ""
    
    	while i<lenght:
    		car = string[i]
    
    		if car != " ":
    			nbr += car
    		else:
    			A.append(int(nbr))
    			nbr = ""
    		i+=1
    	A.append(int(nbr))
    	
    	A = np.array(A)
    	A = np.reshape(A, (48, 48))
    
    	return A
    
    
    
    #LOAD DATA AS ARRAY
    X = []
    Y = []
    
    filename = "data/fer2013.csv"
    
    with open(filename,'r',encoding='utf-8') as file:
    	
    	csv_reader = csv.reader(file, delimiter=",")
    	next(csv_reader)  								#Passe la ligne de titre
    	
    	i=0
    	for row in csv_reader:
    
    		i+=1
    		if i>maxNbrImages: break
    		
    		emotionNbr, stringImage, typeImage = row
    		traitement(emotionNbr, stringImage, typeImage)
    
    		X.append(strToArray(stringImage))
    		Y.append(emotionNbr)
    
    		print(f"Image {i} sur {nbrImages} chargée", end='\r')
    
    X = np.array(X)
    Y = np.array(Y)