<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import cv2
import tensorflow as tf
from tensorflow.keras.layers import Dense,Flatten,Dropout,Conv2D,MaxPooling2D
from tensorflow.keras.models import Sequential,Model
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing.image import load_img
from tensorflow.keras.optimizers import Adam,RMSprop
from tensorflow.keras.losses import categorical_crossentropy,sparse_categorical_crossentropy
from tensorflow.keras.metrics import Accuracy
import matplotlib.pyplot as plt
import os
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.applications.inception_v3 import InceptionV3
from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.applications.vgg16 import VGG16 
from google.colab.patches import cv2_imshow
#Read Data From Directory
Orignal_dir="/content/drive/MyDrive/Internship_TechroticsLab/EyeGazeMovementDetector/EyeData"
Train_data_dir=os.path.join(Orignal_dir,"train")
train_center=os.path.join(Train_data_dir,"center")
train_left=os.path.join(Train_data_dir,"left")
train_right=os.path.join(Train_data_dir,"right")
#left_data=os.listdir(train_left)
#center_data=os.listdir(train_center)
#right_data=os.listdir(train_right)

#print(" Left Data",len(left_data),"\n","Right Data",
#len(right_data),"\n","Center Data", 
#len(center_data))
#train_left_img=[]
#for i in range(len(left_data)):
#  path=train_left+"/"+left_data[i]
#  img=cv2.imread(path)
#  cvt_img=cv2.resize(img,(64,56),3)
#  train_left_img.append(cvt_img)
#train_left_img[0].shape
#train_right_img=[]
#for i in range(len(right_data)):
#  path=train_right+"/"+right_data[i]
#  img=cv2.imread(path)
#  cvt_img=cv2.resize(img,(64,56),3)
#  train_right_img.append(cvt_img)

#train_center_img=[]
#for i in range(len(center_data)):
#  path=train_center+"/"+center_data[i]
#  img=cv2.imread(path)
#  cvt_img=cv2.resize(img,(64,56),3)
#  train_center_img.append(cvt_img)
#for i in range(0,5):
#  cv2_imshow(train_left_img[i])
#  print(train_left_img[i].shape)
#for i in range(0,5):
#  cv2_imshow(train_right_img[i])
#  print(train_right_img[i].shape)
#for i in range (0,5):
#  cv2_imshow(train_center_img[i])
#  print(train_center_img[i].shape)
test_data_dir=os.path.join(Orignal_dir,"test")
test_center_data=os.path.join(test_data_dir,"center")
test_left_data=os.path.join(test_data_dir,"left")
test_right_data=os.path.join(test_data_dir,"right")
#test_left=os.listdir(test_left_data)
#test_right=os.listdir(test_right_data)
#est_center=os.listdir(test_center_data)
#print("left:{}\nright:{}\ncenter:{}".format(len(test_left),len(test_right),len(test_center)))
#test_center_img=[]
#test_right_img=[]
#test_left_img=[]

#for i in range(len(test_center)):
#  path=test_center_data+"/"+test_center[i]
#  img_center=cv2.imread(path)
#  resize_img=cv2.resize(img_center,(64,56),3)
#  test_center_img.append(resize_img)
#for i in range(len(test_left)):
#  path=test_left_data+"/"+test_left[i]
#  img_left=cv2.imread(path)
#  resize_img=cv2.resize(img_left,(64,56),3)
#  test_left_img.append(resize_img)
#for i in range(len(test_right)):
#  path=test_right_data+"/"+test_right[i]
#  img_right=cv2.imread(path)
#  resize_img=cv2.resize(img_right,(64,56),3)
#  test_right_img.append(resize_img)

#path=test_center_data+"/"+test_center[0]
#img=cv2.imread(path)
#img.shape
train_data_gen=ImageDataGenerator(rotation_range=10,
                                  rescale=1./255,
                                  width_shift_range=0.1,
                                  height_shift_range=0.1,
                                  shear_range=0.1,
                                  zoom_range=0.1,
                                  fill_mode="nearest")
test_data_gen=ImageDataGenerator(rescale=1./255)
valid_data_gen=ImageDataGenerator(rescale=1./255)
#train_data_gen.flow_from_directory(Train_data_dir)
#test_data_gen.flow_from_directory(test_data_dir)
train_set=train_data_gen.flow_from_directory(Train_data_dir,target_size=(64,56),batch_size=16,color_mode="grayscale",class_mode="categorical")
test_set=test_data_gen.flow_from_directory(test_data_dir,target_size=(64,56),batch_size=16,color_mode="grayscale",class_mode="categorical")
train_set.class_indices
model=Sequential()
model.add(Conv2D(32,kernel_size=(3,3),strides=1,padding="same",input_shape=(64,56,1),activation="relu"))
model.add(MaxPooling2D((2,2)))

model.add(Conv2D(64,kernel_size=(3,3),strides=1,padding="same",activation="relu"))
model.add(BatchNormalization())
model.add(MaxPooling2D((2,2)))

model.add(Conv2D(128,kernel_size=(3,3),strides=1,padding="same",activation="relu"))
model.add(MaxPooling2D((2,2)))

model.add(Conv2D(256,kernel_size=(3,3),strides=1,padding="same",activation="relu"))
model.add(MaxPooling2D((2,2)))
model.add(Flatten())

model.add(Dense(512,activation="relu"))
model.add(Dropout(0.4))

model.add(Dense(512,activation="relu"))
model.add(Dropout(0.4))


model.add(Dense(3,activation="softmax"))
model.summary()
model.compile(optimizer="Adam",loss="categorical_crossentropy",metrics=["acc"])
callback=EarlyStopping(monitor='val_loss',patience=2)
model.fit(train_set,epochs=8,validation_data=test_set,callbacks=[callback])
model.save("/content/drive/MyDrive/Internship_TechroticsLab/eyegaze.h5")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14968506854390515, 'fraction_numerical': 0.029455353834753614, 'mean_word_length': 7.624600638977636, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '447337', 'license': 'MIT', 'n_tokens_mistral': 2155, 'n_tokens_neox': 2076, 'n_words': 211, 'path': 'TrainingEyeGazeMovementClassification.ipynb', 'repo_name': 'ImranRiazChohan/EyeGazeMovementDetection', 'size': '5398'}