jsteng19 / MNIST_Neural_Net

This is an educational project intended to classify handwritten digits from the MNIST database using only native Python and the NumPy library. Pillow (PIL fork) was used to display the handwritten images for demonstration purposes.
0 stars 0 forks source link

python3 only? is there a way to support both python 2 and 3 pickling simultaneously? #2

Open mkandes opened 6 years ago

mkandes commented 6 years ago
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ python NeuralNetMain.py 
Traceback (most recent call last):
  File "NeuralNetMain.py", line 4, in <module>
    mnist = [pickle.load(open("mnist_train.pickle", "rb")), pickle.load(open("mnist_test.pickle", "rb"))]
  File "/usr/lib/python2.7/pickle.py", line 1384, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 864, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 892, in load_proto
    raise ValueError, "unsupported pickle protocol: %d" % proto
ValueError: unsupported pickle protocol: 3
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ python3 NeuralNetMain.py 
Traceback (most recent call last):
  File "NeuralNetMain.py", line 1, in <module>
    import pickle, numpy
ImportError: No module named 'numpy'
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ apt-cache policy numpy
N: Unable to locate package numpy
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ which python
/usr/bin/python
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ which python3
/usr/bin/python3
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ apt-cache policy python-numpy
python-numpy:
  Installed: 1:1.11.0-1ubuntu1
  Candidate: 1:1.11.0-1ubuntu1
  Version table:
 *** 1:1.11.0-1ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ apt-cache policy python3-numpy
python3-numpy:
  Installed: (none)
  Candidate: 1:1.11.0-1ubuntu1
  Version table:
     1:1.11.0-1ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ apt-get install python3-numpy
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ sudo apt-get install python3-numpy
[sudo] password for mkandes: 
Sorry, try again.
[sudo] password for mkandes: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libllvm3.8 libqmi-glib1 linux-headers-4.4.0-101
  linux-headers-4.4.0-101-generic linux-headers-4.4.0-103
  linux-headers-4.4.0-103-generic linux-headers-4.4.0-104
  linux-headers-4.4.0-104-generic linux-headers-4.4.0-109
  linux-headers-4.4.0-109-generic linux-headers-4.4.0-112
  linux-headers-4.4.0-112-generic linux-headers-4.4.0-21
  linux-headers-4.4.0-21-generic linux-headers-4.4.0-72
  linux-headers-4.4.0-72-generic linux-headers-4.4.0-75
  linux-headers-4.4.0-75-generic linux-headers-4.4.0-78
  linux-headers-4.4.0-78-generic linux-headers-4.4.0-79
  linux-headers-4.4.0-79-generic linux-headers-4.4.0-81
  linux-headers-4.4.0-81-generic linux-headers-4.4.0-83
  linux-headers-4.4.0-83-generic linux-headers-4.4.0-87
  linux-headers-4.4.0-87-generic linux-headers-4.4.0-89
  linux-headers-4.4.0-89-generic linux-headers-4.4.0-91
  linux-headers-4.4.0-91-generic linux-headers-4.4.0-92
  linux-headers-4.4.0-92-generic linux-headers-4.4.0-93
  linux-headers-4.4.0-93-generic linux-headers-4.4.0-96
  linux-headers-4.4.0-96-generic linux-headers-4.4.0-97
  linux-headers-4.4.0-97-generic linux-headers-4.4.0-98
  linux-headers-4.4.0-98-generic linux-image-4.4.0-101-generic
  linux-image-4.4.0-103-generic linux-image-4.4.0-104-generic
  linux-image-4.4.0-109-generic linux-image-4.4.0-112-generic
  linux-image-4.4.0-21-generic linux-image-4.4.0-72-generic
  linux-image-4.4.0-75-generic linux-image-4.4.0-78-generic
  linux-image-4.4.0-79-generic linux-image-4.4.0-81-generic
  linux-image-4.4.0-83-generic linux-image-4.4.0-87-generic
  linux-image-4.4.0-89-generic linux-image-4.4.0-91-generic
  linux-image-4.4.0-92-generic linux-image-4.4.0-93-generic
  linux-image-4.4.0-96-generic linux-image-4.4.0-97-generic
  linux-image-4.4.0-98-generic linux-image-extra-4.4.0-101-generic
  linux-image-extra-4.4.0-103-generic linux-image-extra-4.4.0-104-generic
  linux-image-extra-4.4.0-109-generic linux-image-extra-4.4.0-112-generic
  linux-image-extra-4.4.0-21-generic linux-image-extra-4.4.0-72-generic
  linux-image-extra-4.4.0-75-generic linux-image-extra-4.4.0-78-generic
  linux-image-extra-4.4.0-79-generic linux-image-extra-4.4.0-81-generic
  linux-image-extra-4.4.0-83-generic linux-image-extra-4.4.0-87-generic
  linux-image-extra-4.4.0-89-generic linux-image-extra-4.4.0-91-generic
  linux-image-extra-4.4.0-92-generic linux-image-extra-4.4.0-93-generic
  linux-image-extra-4.4.0-96-generic linux-image-extra-4.4.0-97-generic
  linux-image-extra-4.4.0-98-generic python-lzma python-parsley python-psutil
  python-txsocksx snap-confine tor tor-geoipdb torsocks ubuntu-core-launcher
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  python-numpy-doc python3-nose python3-numpy-dbg
The following NEW packages will be installed:
  python3-numpy
0 upgraded, 1 newly installed, 0 to remove and 42 not upgraded.
Need to get 1,762 kB of archives.
After this operation, 9,589 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 python3-numpy amd64 1:1.11.0-1ubuntu1 [1,762 kB]
Fetched 1,762 kB in 5s (298 kB/s)          
Selecting previously unselected package python3-numpy.
(Reading database ... 1029987 files and directories currently installed.)
Preparing to unpack .../python3-numpy_1%3a1.11.0-1ubuntu1_amd64.deb ...
Unpacking python3-numpy (1:1.11.0-1ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up python3-numpy (1:1.11.0-1ubuntu1) ...
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$ python3 NeuralNetMain.py 
accuracy: 0.109
Batch size:  150  learning constant:  1
accuracy: 0.613
mkandes@castlebravo:~/Dropbox/projects/MNIST_Neural_Net$
jsteng19 commented 6 years ago

I have not been able to find a way to support pickling on both versions simultaneously; it looks like the best way to address this would be to create separate .pickle files in the Python 2 protocol. A program to convert between a Python 3 and 2 .pickle file or vice versa should only be a few lines.