Skip to content

Commit

Permalink
Encoding codec used by Python 3 pickle (#13)
Browse files Browse the repository at this point in the history
* fixed decode error while using Python 3

* minor fix

* encoding as kwarg
  • Loading branch information
hasibzunair authored and tgsmith61591 committed Jul 31, 2019
1 parent 8e75e2c commit 0863b0b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions examples/MNIST example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
"import pickle\n",
"import subprocess\n",
"import os\n",
"import sys \n",
"\n",
"rs = RandomState(seed)\n",
"fl = 'data/mnist/mnist.pkl'\n",
Expand All @@ -401,7 +402,14 @@
"\n",
"def _load_from_pickle():\n",
" with open(fl, 'rb') as f:\n",
" d = pickle.load(f)\n",
" if (sys.version_info > (3, 0)):\n",
" # content of file encoded using Python 3 \n",
" print(\"Encoded using Python 3\")\n",
" d = pickle.load(f, encoding=\"latin1\")\n",
" else:\n",
" # content of file encoded using Python 2\n",
" print(\"Encoded using Python 2\")\n",
" d = pickle.load(f)\n",
" \n",
" X, y = d['data'], d['labels']\n",
" min_mask = y == min_label\n",
Expand Down Expand Up @@ -1020,23 +1028,23 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [Root]",
"display_name": "Python 3",
"language": "python",
"name": "Python [Root]"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 2
}

0 comments on commit 0863b0b

Please sign in to comment.