MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / main

Function main

samples/python/scripts/download_mnist_pgms.py:46–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 return list(raw_buf[8:].astype(np.int32).reshape(num_labels))
45
46def main():
47 parser = argparse.ArgumentParser(description="Extracts 10 PGM files from the MNIST dataset", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
48 parser.add_argument("-o", "--output", help="Path to the output directory.", default=os.getcwd())
49
50 args, _ = parser.parse_known_args()
51
52 with urllib.request.urlopen("http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz") as res:
53 data = load_mnist_data(gzip.decompress(res.read()))
54
55 with urllib.request.urlopen("http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz") as res:
56 labels = load_mnist_labels(gzip.decompress(res.read()))
57
58 output_dir = args.output
59
60 # Find one image for each digit.
61 for i in range(10):
62 index = labels.index(i)
63 image = Image.fromarray(data[index], mode="L")
64 path = os.path.join(output_dir, "{:}.pgm".format(i))
65 image.save(path)
66
67if __name__ == '__main__':
68 main()

Callers 1

Calls 4

load_mnist_dataFunction · 0.85
load_mnist_labelsFunction · 0.85
readMethod · 0.80
saveMethod · 0.45

Tested by

no test coverage detected