diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..254d351 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*ubyte.gz +image.npy +image.png \ No newline at end of file diff --git a/__pycache__/mnist.cpython-37.pyc b/__pycache__/mnist.cpython-37.pyc new file mode 100644 index 0000000..0939a40 Binary files /dev/null and b/__pycache__/mnist.cpython-37.pyc differ diff --git a/convert.py b/convert.py new file mode 100644 index 0000000..64caeee --- /dev/null +++ b/convert.py @@ -0,0 +1,71 @@ +# MIT License + +# Copyright (c) 2017 Hyeonseok Jung + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + +# ALL RIGHTS TO ORIGINAL OWNER +# https://github.com/hsjeong5/MNIST-for-Numpy + +# Modified by Steven Furgurson +# https://github.com/theDweeb +import mnist +import numpy as np +import imageio +import os.path +from PIL import Image + +# Check if MNIST dataset has been downloaded +isDownloaded = ( + os.path.exists("train-images-idx3-ubyte.gz") and + os.path.exists("train-images-idx3-ubyte.gz") and + os.path.exists("train-images-idx3-ubyte.gz") and + os.path.exists("train-images-idx3-ubyte.gz") +) + +if(not isDownloaded): + print("Downloading files") + mnist.init() + +print("Files downloaded") + +# Hold MNIST dataset +# x_train: Training images +# t_train: Training labels +# x_test: Testing images +# t_test = Testing labels +x_train, t_train, x_test, t_test = mnist.load() + +# Pull a image to test for MLP +# Just adjust the left index +image = x_test[0,:] +image.resize((28,28)) + +# For my MLP I used np.int32 for image. +# Make sure the data type matches for the vector +npimage = np.asarray(image, dtype=np.int32) + +np.save("image", npimage) + +# Shows image for labeling +img = Image.fromarray(image) +img.save('image.png') +img.show() \ No newline at end of file diff --git a/mnist.pkl b/mnist.pkl new file mode 100644 index 0000000..63eec84 Binary files /dev/null and b/mnist.pkl differ