(buffer)
| 37 | |
| 38 | # Returns a list of length num_images |
| 39 | def load_mnist_labels(buffer): |
| 40 | raw_buf = np.fromstring(buffer, dtype=np.uint8) |
| 41 | # Make sure the magic number is what we expect |
| 42 | assert raw_buf[0:4].view(">i4")[0] == 2049 |
| 43 | num_labels = raw_buf[4:8].view(">i4")[0] |
| 44 | return list(raw_buf[8:].astype(np.int32).reshape(num_labels)) |
| 45 | |
| 46 | def main(): |
| 47 | parser = argparse.ArgumentParser(description="Extracts 10 PGM files from the MNIST dataset", formatter_class=argparse.ArgumentDefaultsHelpFormatter) |