Sleep Detection(Image Labeling)

parent 9094370c
Image Labelling
import tensorflow as tf
import cv2
import os
import matplotlib.pyplot as plt
import numpy as np
img_array = cv2.imread("C:/Users/Thila/AppData/Local/Programs/Python/Python39/Scripts/sleep/Test/Closed_Eyes/s0001_00097_0_0_0_0_0_01.png", cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
img_array.shape
Datadirectory = "C:/Users/Thila/AppData/Local/Programs/Python/Python39/Scripts/sleep/Eyes/"
Classes = ["Closed_Eyes","Open_Eyes"]
for category in Classes:
path = os.path.join(Datadirectory, category)
for img in os.listdir(path):
img_array = cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
backtorgb = cv2.cvtColor(img_array,cv2.COLOR_GRAY2RGB)
plt.imshow(img_array, cmap="gray")
plt.show()
break
break
img_size = 224
new_array= cv2.resize(backtorgb, (img_size, img_size))
plt.imshow(new_array, cmap="gray")
plt.show()
training_Data = []
def create_training_Data():
for category in Classes:
path = os.path.join(Datadirectory, category)
class_num = Classes.index(category)
for img in os.listdir(path):
try:
img_array = cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
backtorgb = cv2.cvtColor(img_array,cv2.COLOR_GRAY2RGB)
new_array= cv2.resize(backtorgb, (img_size,img_size))
training_Data.append([new_array,class_num])
except Exception as e:
pass
create_training_Data()
print(len(training_Data))
import random
random.shuffle(training_Data)
X = []
y = []
for features,label in training_Data:
X.append(features)
y.append(label)
X = np.array(X).reshape(-1, img_size, img_size, 3)
X.shape
X= X/255.0;
Y= np.array(y)
import pickle
pickle_out = open("X.pickle", "wb")
pickle.dump(X, pickle_out)
pickle_out.close()
pickle_out = open("y.pickle", "wb")
pickle.dump(y, pickle_out)
pickle_out.close()
pickle_in = open("X.pickle","rb")
X = pickle.load(pickle_in)
pickle_in = open("y.pickle","rb")
y = pickle.load(pickle_in)
\ 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