Skip to content

Instantly share code, notes, and snippets.

@PhilipPurwoko
Last active December 9, 2020 02:06
Show Gist options
  • Save PhilipPurwoko/5ecf2c27444a2cb97bd8eedeb10ffb04 to your computer and use it in GitHub Desktop.
Save PhilipPurwoko/5ecf2c27444a2cb97bd8eedeb10ffb04 to your computer and use it in GitHub Desktop.
import os
import random
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
keras = tf.keras
def loading_data():
dirname = 'dataset/'
dirtype = ['train/', 'valid/']
dirclass = ['with_mask/', 'without_mask/']
x_train = []
y_train = []
x_test = []
y_test = []
for typ in dirtype:
for cls in dirclass:
for i in os.listdir(dirname+typ+cls):
if typ == 'train/':
x_train.append(dirname+'train/'+cls+i)
y_train.append(cls[:-1])
else:
x_test.append(dirname+'valid/'+cls+i)
y_test.append(cls[:-1])
return np.array(x_train),np.array(y_train),np.array(x_test),np.array(y_test)
# Run loading_data() function
x_train,y_train,x_test,y_test = loading_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment