import tensorflow as tf
from tensorflow.keras.preprocessing import image_dataset_from_directory
BATCH_SIZE = 32
IMG_HEIGHT = 180
IMG_WIDTH = 180
BASE_PATH = "./traffic_Data/DATA"
AUTOTUNE = tf.data.AUTOTUNE
train_ds = image_dataset_from_directory(BASE_PATH, image_size=(IMG_HEIGHT, IMG_WIDTH), batch_size=BATCH_SIZE)
class_names = train_ds.class_names
NUM_CLASSES = len(class_names)
def normalize_and_center(image, label):
image = tf.cast(image/255. - 0.5, tf.float32)
return image, label
train_ds_norm = train_ds.map(normalize_and_center)
train_ds_norm = train_ds_norm.cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE)