Skip to content

Instantly share code, notes, and snippets.

@nidhaloff
Created August 23, 2021 16:10
Show Gist options
  • Save nidhaloff/6537bb4c76790af86f0567435c8618b8 to your computer and use it in GitHub Desktop.
Save nidhaloff/6537bb4c76790af86f0567435c8618b8 to your computer and use it in GitHub Desktop.
A python script to automate the creation of a mnist dataset in csv format from raw mnist images
import os
for name in ['training', 'testing']:
with open('mnist_dataset_{}.csv'.format(name), 'w') as output_file:
print('=== creating {} dataset ==='.format(name))
output_file.write('image_path,label\n')
for i in range(10):
path = '{}/{}'.format(name, i)
for file in os.listdir(path):
if file.endswith(".png"):
output_file.write('{},{}\n'.format(os.path.join(path, file), str(i)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment