diff --git a/13_convolutional_neural_networks.ipynb b/13_convolutional_neural_networks.ipynb index 0c9378e..94bf961 100644 --- a/13_convolutional_neural_networks.ipynb +++ b/13_convolutional_neural_networks.ipynb @@ -455,7 +455,7 @@ "source": [ "import sys\n", "import tarfile\n", - "import urllib.request\n", + "from six.moves import urllib\n", "\n", "TF_MODELS_URL = \"http://download.tensorflow.org/models\"\n", "INCEPTION_V3_URL = TF_MODELS_URL + \"/inception_v3_2016_08_28.tar.gz\"\n", diff --git a/14_recurrent_neural_networks.ipynb b/14_recurrent_neural_networks.ipynb index 2f2f541..4a1b2ad 100644 --- a/14_recurrent_neural_networks.ipynb +++ b/14_recurrent_neural_networks.ipynb @@ -1476,13 +1476,27 @@ "source": [ "from six.moves import urllib\n", "\n", + "import errno\n", "import os\n", "import zipfile\n", - "import urllib.request\n", "\n", "WORDS_PATH = \"datasets/words\"\n", "WORDS_URL = 'http://mattmahoney.net/dc/text8.zip'\n", "\n", + "def mkdir_p(path):\n", + " \"\"\"Create directories, ok if they already exist.\n", + " \n", + " This is for python 2 support. In python >=3.2, simply use:\n", + " >>> os.makedirs(path, exist_ok=True)\n", + " \"\"\"\n", + " try:\n", + " os.makedirs(path)\n", + " except OSError as exc:\n", + " if exc.errno == errno.EEXIST and os.path.isdir(path):\n", + " pass\n", + " else:\n", + " raise\n", + "\n", "def fetch_words_data(words_url=WORDS_URL, words_path=WORDS_PATH):\n", " os.makedirs(words_path, exist_ok=True)\n", " zip_path = os.path.join(words_path, \"words.zip\")\n",