python MNIST dataset "no attribute train_images"
Question:
I’m using python3.7 and trying to use MNIST train data images.
Instead of using PyTorch, tf, kears framwork which help to use dataset easily, I tried using mnist module directly.
I was following a tutorial for CNN, there was
import mnist
Then I tried “pip install python-mnist” (after uninstall python-mnist, I ‘ve done ‘pip install mnist’) and it was downloaded successfully.
then I typed same codes to make train images.
train_images = mnist.train_images()
however it says “AttributeError: module ‘mnist’ has no attribute ‘train_images'”
I checked print(mnist) and it gives the path,
but print(mnist.train_images) gives same error message.
As far as I know, it is possible to use functions in ‘init.py’, but it doesn’t seem to.. or what am I getting wrong?
++ furthermore, even if I deleted mnist folder, and run the same code, it still exists printing out the same path, which I believe it’s supposed to print ‘there is no module mnist’ .. what kind of knowledge am I missing now..? 🙁
Thank you in advance,
Answers:
Actually, you just need to follow the instruction on the Github page of MNIST (link).
After installing the lib with pip install python-mnist
, you should clone the repo and execute a script to download the mnist data:
git clone https://github.com/sorki/python-mnist
cd python-mnist
./get_data.sh
You data will be saved in a folder named data
, after that you can call it in code using:
from mnist import MNIST
mndata = MNIST('data/')
mndata.gz = False
images, labels = mndata.load_training()
The images
variable is a list of lists of pixels, you should reshape it after that to see the images.
NB: If I were you, I will just use pytorch
or Keras
because is a lot easier and they do the job for you. After that, if you dont want to use tensors, you can just convert them back to numpy arrays.
Also note if you have a file ./mnist.py
in your local folder, then this will take over and prevent you from importing the desired mnist
library.
just use
\
\\
from mnist import *
x_train=train_images()
y_train=train_labels()
I had the same problem! The reason was in installing python-mnist (for other program) after install mnist. They have common name file. When I uninstalled python-mnist the problem is dissapear!
I’m using python3.7 and trying to use MNIST train data images.
Instead of using PyTorch, tf, kears framwork which help to use dataset easily, I tried using mnist module directly.
I was following a tutorial for CNN, there was
import mnist
Then I tried “pip install python-mnist” (after uninstall python-mnist, I ‘ve done ‘pip install mnist’) and it was downloaded successfully.
then I typed same codes to make train images.
train_images = mnist.train_images()
however it says “AttributeError: module ‘mnist’ has no attribute ‘train_images'”
I checked print(mnist) and it gives the path,
but print(mnist.train_images) gives same error message.
As far as I know, it is possible to use functions in ‘init.py’, but it doesn’t seem to.. or what am I getting wrong?
++ furthermore, even if I deleted mnist folder, and run the same code, it still exists printing out the same path, which I believe it’s supposed to print ‘there is no module mnist’ .. what kind of knowledge am I missing now..? 🙁
Thank you in advance,
Actually, you just need to follow the instruction on the Github page of MNIST (link).
After installing the lib with pip install python-mnist
, you should clone the repo and execute a script to download the mnist data:
git clone https://github.com/sorki/python-mnist
cd python-mnist
./get_data.sh
You data will be saved in a folder named data
, after that you can call it in code using:
from mnist import MNIST
mndata = MNIST('data/')
mndata.gz = False
images, labels = mndata.load_training()
The images
variable is a list of lists of pixels, you should reshape it after that to see the images.
NB: If I were you, I will just use pytorch
or Keras
because is a lot easier and they do the job for you. After that, if you dont want to use tensors, you can just convert them back to numpy arrays.
Also note if you have a file
./mnist.py
in your local folder, then this will take over and prevent you from importing the desiredmnist
library.
just use
\
\\
from mnist import *
x_train=train_images()
y_train=train_labels()
I had the same problem! The reason was in installing python-mnist (for other program) after install mnist. They have common name file. When I uninstalled python-mnist the problem is dissapear!