09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2

If you want to save a model together with its weights and the optimization

parameters, then you simply use:

model.save('my_model.h5') # save

model = tf.keras.models.load_model('my_model.h5') #restore

Training from tf.data.datasets

Another benefit of using TensorFlow 2.x is the introduction of TensorFlow datasets

as a principled mechanism to deal with heterogeneous (large) datasets in different

categories such as audio, image, video, text, and translation. Let's first use pip to

install tensorflow-datasets:

pip install tensorflow-datasets

As of September 2019 there are already 85+ commonly used

datasets available, but more are planned to be added in https://

www.tensorflow.org/datasets/datasets.

Then, we can list all the datasets available, and load MNIST together with metadata:

import tensorflow as tf

import tensorflow_datasets as tfds

# See all registered datasets

builders = tfds.list_builders()

print(builders)

# Load a given dataset by name, along with the DatasetInfo metadata

data, info = tfds.load("mnist", with_info=True)

train_data, test_data = data['train'], data['test']

print(info)

Then, we get the following lists of datasets:

['bair_robot_pushing_small', 'cats_vs_dogs', 'celeb_a', 'celeb_a_hq',

'cifar10', 'cifar100', 'coco2014', 'diabetic_retinopathy_detection',

'dummy_dataset_shared_generator', 'dummy_mnist', 'fashion_mnist', 'image_

label_folder', 'imagenet2012', 'imdb_reviews', 'lm1b', 'lsun', 'mnist',

'moving_mnist', 'nsynth', 'omniglot', 'open_images_v4', 'quickdraw_

bitmap', 'squad', 'starcraft_video', 'svhn_cropped', 'tf_flowers', 'wmt_

translate_ende', 'wmt_translate_enfr']

[ 69 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!