Last active
September 20, 2020 15:09
-
-
Save RITIK-12/f6b6ef4adcbce52d6e05fb329eb76bc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# initialize the initial learning rate, number of epochs to train for, | |
# and batch size | |
INIT_LR = 1e-4 | |
EPOCHS = 20 | |
BS = 32 | |
# grab the list of images in our dataset directory, then initialize | |
# the list of data (i.e., images) and class images | |
imagePaths = list(paths.list_images('../input/face-mask-detection-data')) | |
data = [] | |
labels = [] | |
# loop over the image paths | |
for imagePath in imagePaths: | |
# extract the class label from the filename | |
label = imagePath.split(os.path.sep)[-2] | |
# load the input image (224x224) and preprocess it | |
image = load_img(imagePath, target_size=(224, 224)) | |
image = img_to_array(image) | |
image = preprocess_input(image) | |
# update the data and labels lists, respectively | |
data.append(image) | |
labels.append(label) | |
print("No. of images loaded: {}".format(len(data))) | |
# convert the data and labels to NumPy arrays | |
data = np.array(data, dtype="float32") | |
labels = np.array(labels) | |
# perform one-hot encoding on the labels | |
lb = LabelBinarizer() | |
labels = lb.fit_transform(labels) | |
labels = to_categorical(labels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment