How to use the deepface.dataset.get_train_test_dataset function in deepface

To help you get started, we’ve selected a few deepface examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github swghosh / DeepFace / training / train_on_tpu.py View on Github external
Initialise the TPU
and create the required
tf.distribute.Strategy
"""
keras.backend.clear_session()

tpu_cluster = tf.contrib.cluster_resolver.TPUClusterResolver(tpu=TPU_WORKER)
tf.contrib.distribute.initialize_tpu_system(tpu_cluster)
strategy = tf.contrib.distribute.TPUStrategy(tpu_cluster)

"""
Prepare the data pipeline
for train, val images
"""
from deepface import dataset
train, val = dataset.get_train_test_dataset(CL_PATH, DATASET_PATH, IMAGE_SIZE, BATCH_SIZE)
# these are essential values that have to be set
# in order to determine the right number of steps per epoch
train_samples, val_samples = 2307424, 25893
# this value is set so as to ensure
#  proper shuffling of dataset
dataset.SHUFFLE_BUFFER = train_samples
assert train.num_classes == val.num_classes == NUM_CLASSES

"""
Add some tf.keras.callbacks.Callback(s)
to enhance op(s)
like TensorBoard visualisation
and ReduceLR
"""
reduce_lr = keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.1,
    patience=1, min_lr=0.0001, verbose=1) # mandatory step in training, as specified in paper