MCPcopy Index your code
hub / github.com/tensorflow/datasets / _load_data

Function _load_data

tensorflow_datasets/image_classification/cifar.py:207–225  ·  view source on GitHub ↗

Yields (labels, np_image) tuples.

(path, labels_number=1)

Source from the content-addressed store, hash-verified

205
206
207def _load_data(path, labels_number=1):
208 """Yields (labels, np_image) tuples."""
209 with tf.io.gfile.GFile(path, "rb") as f:
210 data = f.read()
211 offset = 0
212 max_offset = len(data) - 1
213 while offset < max_offset:
214 labels = np.frombuffer(
215 data, dtype=np.uint8, count=labels_number, offset=offset
216 ).reshape((labels_number,))
217 # 1 byte per label, 1024 * 3 = 3072 bytes for the image.
218 offset += labels_number
219 img = (
220 np.frombuffer(data, dtype=np.uint8, count=3072, offset=offset)
221 .reshape((3, _CIFAR_IMAGE_SIZE, _CIFAR_IMAGE_SIZE))
222 .transpose((1, 2, 0))
223 )
224 offset += 3072
225 yield labels, img

Callers 1

_generate_examplesMethod · 0.70

Calls 1

readMethod · 0.45

Tested by

no test coverage detected