09.05.2023 Views

pdfcoffee

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TensorFlow 1.x and 2.x

In addition, we get the metainfo for MNIST:

tfds.core.DatasetInfo(

name='mnist',

version=1.0.0,

description='The MNIST database of handwritten digits.',

urls=['http://yann.lecun.com/exdb/mnist/'],

features=FeaturesDict({

'image': Image(shape=(28, 28, 1), dtype=tf.uint8),

'label': ClassLabel(shape=(), dtype=tf.int64, num_classes=10)

},

total_num_examples=70000,

splits={

'test': <tfds.core.SplitInfo num_examples=10000>,

'train': <tfds.core.SplitInfo num_examples=60000>

},

supervised_keys=('image', 'label'),

citation='"""

@article{lecun2010mnist,

title={MNIST handwritten digit database},

author={LeCun, Yann and Cortes, Corinna and Burges, CJ},

journal={ATT Labs [Online]. Available: http://yann. lecun.

com/exdb/mnist},

volume={2},

year={2010}

}

)

"""',

Sometimes it is useful to create a dataset from a NumPy array. Let's see how in this

code fragment, which uses tf.data.Dataset.from_tensor_slices():

import tensorflow as tf

import numpy as np

num_items = 100

num_list = np.arange(num_items)

# create the dataset from numpy array

num_list_dataset = tf.data.Dataset.from_tensor_slices(num_list)

We can also download a dataset, shuffle and batch the data, and take a slice from the

generator as shown in this example:

datasets, info = tfds.load('imdb_reviews', with_info=True, as_

[ 70 ]

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

Saved successfully!

Ooh no, something went wrong!