Yields (labels, np_image) tuples.
(path, labels_number=1)
| 205 | |
| 206 | |
| 207 | def _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 |
no test coverage detected