MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / dataset

Function dataset

tensorflow/lite/tutorials/dataset.py:86–111  ·  view source on GitHub ↗

Download and parse MNIST dataset.

(directory, images_file, labels_file)

Source from the content-addressed store, hash-verified

84
85
86def dataset(directory, images_file, labels_file):
87 """Download and parse MNIST dataset."""
88
89 images_file = download(directory, images_file)
90 labels_file = download(directory, labels_file)
91
92 check_image_file_header(images_file)
93 check_labels_file_header(labels_file)
94
95 def decode_image(image):
96 # Normalize from [0, 255] to [0.0, 1.0]
97 image = tf.decode_raw(image, tf.uint8)
98 image = tf.cast(image, tf.float32)
99 image = tf.reshape(image, [784])
100 return image / 255.0
101
102 def decode_label(label):
103 label = tf.decode_raw(label, tf.uint8) # tf.string -> [tf.uint8]
104 label = tf.reshape(label, []) # label is a scalar
105 return tf.to_int32(label)
106
107 images = tf.data.FixedLengthRecordDataset(
108 images_file, 28 * 28, header_bytes=16).map(decode_image)
109 labels = tf.data.FixedLengthRecordDataset(
110 labels_file, 1, header_bytes=8).map(decode_label)
111 return tf.data.Dataset.zip((images, labels))
112
113
114def train(directory):

Callers 15

trainFunction · 0.70
testFunction · 0.70
GetNextInternalMethod · 0.50
GetNextInternalMethod · 0.50
GetNextInternalMethod · 0.50
MakeRowRangeMethod · 0.50
MakeRowRangeMethod · 0.50
MakeRowRangeMethod · 0.50
MakeFilterMethod · 0.50

Calls 5

check_image_file_headerFunction · 0.85
check_labels_file_headerFunction · 0.85
downloadFunction · 0.70
mapMethod · 0.45
zipMethod · 0.45

Tested by 12

GetNextInternalMethod · 0.40
ChooseFastestIteratorMethod · 0.40
InitializeMethod · 0.40
GetNextInternalMethod · 0.40
CreateNodeMethod · 0.40
RestoreInternalMethod · 0.40
ChooseFastestIteratorMethod · 0.40
InitializeMethod · 0.40
GetNextInternalMethod · 0.40
RestoreInternalMethod · 0.40