<gh_stars>0
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
"""Load images as dataset readable by tensorflow 
for trainign and validation
"""

img_height = 224
img_width = 224

def read_data(main_directory):
    global img_height
    global img_width

    train_images = tf.keras.utils.image_dataset_from_directory(
    main_directory, 
    validation_split = 0.2,
    subset = 'training',
	labels='inferred', 
	label_mode='categorical',
    seed = 42, 
    class_names=None, 
	color_mode='rgb', 
	image_size=(img_width, img_height),
)
    validation_images = tf.keras.utils.image_dataset_from_directory(
    main_directory, 
    validation_split = 0.2,
    subset = 'validation',
	labels='inferred', 
	label_mode='categorical',
    seed = 42,
    class_names=None, 
	color_mode='rgb', 
	image_size=(img_width, img_height),
)
    return train_images, validation_images


def visualize_example(dataset):
	class_names = dataset.class_names
	plt.figure(figsize=(10, 10))
	for images, labels in dataset.take(1):
		for i in range(9):
			ax = plt.subplot(3, 3, i + 1)
			plt.imshow(images[i].numpy().astype("uint8"))
			plt.title(class_names[np.argmax(labels[i])])
			plt.axis("off")
	plt.show()


def normalize_data(image,label):
    image = tf.cast(image/255., tf.float32)
    return image,label

def main():
    MAIN_PATH = "./data"
    train_set, validation_set = read_data(MAIN_PATH)

    normal_train = normalize_data(train_set)
    normal_validation = normalize_data(validation_set)

if __name__=="__main__":
	main()
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
"""Load images as dataset readable by tensorflow 
for trainign and validation
"""

img_height = 224
img_width = 224

def read_data(main_directory):
    global img_height
    global img_width

    train_images = tf.keras.utils.image_dataset_from_directory(
    main_directory, 
    validation_split = 0.2,
    subset = 'training',
	labels='inferred', 
	label_mode='categorical',
    seed = 42, 
    class_names=None, 
	color_mode='rgb', 
	image_size=(img_width, img_height),
)
    validation_images = tf.keras.utils.image_dataset_from_directory(
    main_directory, 
    validation_split = 0.2,
    subset = 'validation',
	labels='inferred', 
	label_mode='categorical',
    seed = 42,
    class_names=None, 
	color_mode='rgb', 
	image_size=(img_width, img_height),
)
    return train_images, validation_images


def visualize_example(dataset):
	class_names = dataset.class_names
	plt.figure(figsize=(10, 10))
	for images, labels in dataset.take(1):
		for i in range(9):
			ax = plt.subplot(3, 3, i + 1)
			plt.imshow(images[i].numpy().astype("uint8"))
			plt.title(class_names[np.argmax(labels[i])])
			plt.axis("off")
	plt.show()


def normalize_data(image,label):
    image = tf.cast(image/255., tf.float32)
    return image,label

def main():
    MAIN_PATH = "./data"
    train_set, validation_set = read_data(MAIN_PATH)

    normal_train = normalize_data(train_set)
    normal_validation = normalize_data(validation_set)

if __name__=="__main__":
	main()
Load images as dataset readable by tensorflow  for trainign and validation