<jupyter_start><jupyter_text><jupyter_code>!git clone  https://github.com/tiagosardi/emotionrecognition.git
!pip install -q kaggle
from google.colab import files
files.upload()
! mkdir ~/.kaggle
! cp kaggle.json ~/.kaggle/
!chmod 600 ~/.kaggle/kaggle.json
!kaggle datasets list
!kaggle competitions download -c challenges-in-representation-learning-facial-expression-recognition-challenge
!unzip train.csv.zip -d train
!unzip test.csv.zip -d test
!tar -vzxf fer2013.tar.gz
import cv2
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow
data = pd.read_csv('fer2013/fer2013.csv')
data.tail()
plt.figure(figsize=(12,6))
plt.hist(data['emotion'], bins= 30)
plt.title('Img X emotions')
height, width = 48,48
faces = []
samples = 0
for pixel_sequence in  pixels:
  face = [int(pixel) for pixel in pixel_sequence.split(' ')]
  face = np.asarray(face).reshape(height,width)
  faces.append(face)

  if(samples<10):
    cv2_imshow(face)
  amostras+=1
X_train, X_test , y_train, y_test = train_test_split(faces, emocoes, test_size = .1, random_state = 42)
X_train, X_val ,y_train, y_val = train_test_split (X_train, y_train , test_size = .1, random_state = 41)


print("Numero de imagens no conjunto de treinamento: ", len(X_train))
print("Numero de imagens no conjunto de teste: ", len(X_test))
print("Numero de imagens no conjunto de validacao: ", len(X_val))
np.save('mod_xtest' , X_test)
np.save('mod_ytest', y_test)
num_features = 64
num_labels = 7
batch_size = 64
epochs = 100
width, height = 48,48

model.compile (loss= 'categorical_crossentropy',
               optimizer = Adam(lr=.001, beta_1=.9, beta_2= .999, epsilon=1e-7),
               metrics=['accuracy'])

arquivo_modelo = 'modelo_01_expressoes.h5'
arquivo_modelo_json = 'modelo_01_expressoes.json'
lr_reducer = ReduceLROnPlateau(monitor='val_loss', factor = .9, patience=3, verbose = 1)
early_stopper = EarlyStoppping(monitor='val_loss', min_delta=0,patience=8, verbose=1, mode='auto')
checkpointer = ModelCheckpoint(arquivo_modelo, monitor='val_loss', verbose=1, save_best_only=True)
history = model.fit(np.array(X_train), np.array(y_train),
                    batch_size = batch_size,
                    epochs = epochs,
                    verbose = 1,
                    validation_data = (np.array(X_val),np.array(y_val)),
                    shuffle = True,
                    callbacks = [lr_reducer, early_stopper, checkpointer])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12570965125709652, 'fraction_numerical': 0.029197080291970802, 'mean_word_length': 4.215644820295983, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '164970', 'license': 'MIT', 'n_tokens_mistral': 948, 'n_tokens_neox': 881, 'n_words': 195, 'path': 'human_emotion_detection.ipynb', 'repo_name': 'tiagosardi/emotionrecognition', 'size': '2466'}