From 0863b0b94897ad8d8d9184b792cdb275627e1ac4 Mon Sep 17 00:00:00 2001 From: Hasib Zunair Date: Wed, 31 Jul 2019 07:31:39 +0600 Subject: [PATCH] Encoding codec used by Python 3 pickle (#13) * fixed decode error while using Python 3 * minor fix * encoding as kwarg --- examples/MNIST example.ipynb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/examples/MNIST example.ipynb b/examples/MNIST example.ipynb index 349a924..0ce668b 100644 --- a/examples/MNIST example.ipynb +++ b/examples/MNIST example.ipynb @@ -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", @@ -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", @@ -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 }