import tensorflow as tf
import random
import cv2, os
import numpy as np
import matplotlib.pyplot as plt
data = "/content/drive/MyDrive/data_sample"
Classes = ["facemask", "nofacemask"]
#Reading the imagesand then convert them in to array
img_size = 224
Training_Data = [] #data
def Create_Training_Data():
for category in Classes:
path = os.path.join(data,category)
class_no = Classes.index(category)
for img in os.listdir(path):
try:
img_Array = cv2.imread(os.path.join(path,img))
new_array = cv2.resize(img_Array, (img_size, img_size))
Training_Data.append([new_array, class_no])
except Exception as e:
pass
Create_Training_Data()
print(len(Training_Data))
random.shuffle(Training_Data)
X = [] #datas
y = [] #label
for features,label in Training_Data:
X.append(features)
y.append(label)
X = np.array(X).reshape(-1, img_size, img_size, 3)
X= X/255.0; #normalising
Y = np.array(y)
import pickle
#storing data
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)
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
model = tf.keras.applications.mobilenet.MobileNet()
model.summary()
base_input = model.layers[0].input
base_output = model.layers[-4].output
Flat_layer = layers.Flatten()(base_output)
final_output = layers.Dense(1)(Flat_layer) ##only 0 or 1
final_ouput = layers.Activation('sigmoid')(final_output)
new_model = keras.Model(inputs = base_input, outputs = final_output)
new_model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
new_model.fit(X,Y, epochs = 20, validation_split = 0.1)
This is the code that I tried to execute for the training of my model. I use google collab for exectuion.
But I get output as while my data sample contains 1878. Why I'm getting only 53/53?
I am referring to one video from youtube where he has a 1950 sample and at the model.fit he having 1775/1775 but in my case, I'm having 1878 and I'm getting only 53/53 while (as you can see in attached image).