Commit 3e34dbde authored by Fahim Mannan's avatar Fahim Mannan
Browse files

deeplab_demo notebook py2 and py3 support

parent 08af7775
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
"#@title Imports\n", "#@title Imports\n",
"\n", "\n",
"import os\n", "import os\n",
"import StringIO\n", "from io import BytesIO\n",
"import tarfile\n", "import tarfile\n",
"import tempfile\n", "import tempfile\n",
"import urllib\n", "from six.moves import urllib\n",
"\n", "\n",
"from matplotlib import gridspec\n", "from matplotlib import gridspec\n",
"from matplotlib import pyplot as plt\n", "from matplotlib import pyplot as plt\n",
...@@ -238,13 +238,13 @@ ...@@ -238,13 +238,13 @@
"tf.gfile.MakeDirs(model_dir)\n", "tf.gfile.MakeDirs(model_dir)\n",
"\n", "\n",
"download_path = os.path.join(model_dir, _TARBALL_NAME)\n", "download_path = os.path.join(model_dir, _TARBALL_NAME)\n",
"print 'downloading model, this might take a while...'\n", "print('downloading model, this might take a while...')\n",
"urllib.urlretrieve(_DOWNLOAD_URL_PREFIX + _MODEL_URLS[MODEL_NAME],\n", "urllib.request.urlretrieve(_DOWNLOAD_URL_PREFIX + _MODEL_URLS[MODEL_NAME],\n",
" download_path)\n", " download_path)\n",
"print 'download completed! loading DeepLab model...'\n", "print('download completed! loading DeepLab model...')\n",
"\n", "\n",
"MODEL = DeepLabModel(download_path)\n", "MODEL = DeepLabModel(download_path)\n",
"print 'model loaded successfully!'" "print('model loaded successfully!')"
] ]
}, },
{ {
...@@ -292,14 +292,14 @@ ...@@ -292,14 +292,14 @@
"def run_visualization(url):\n", "def run_visualization(url):\n",
" \"\"\"Inferences DeepLab model and visualizes result.\"\"\"\n", " \"\"\"Inferences DeepLab model and visualizes result.\"\"\"\n",
" try:\n", " try:\n",
" f = urllib.urlopen(url)\n", " f = urllib.request.urlopen(url)\n",
" jpeg_str = f.read()\n", " jpeg_str = f.read()\n",
" orignal_im = Image.open(StringIO.StringIO(jpeg_str))\n", " orignal_im = Image.open(BytesIO(jpeg_str))\n",
" except IOError:\n", " except IOError:\n",
" print 'Cannot retrieve image. Please check url: ' + url\n", " print('Cannot retrieve image. Please check url: ' + url)\n",
" return\n", " return\n",
"\n", "\n",
" print 'running deeplab on image %s...' % url\n", " print('running deeplab on image %s...' % url)\n",
" resized_im, seg_map = MODEL.run(orignal_im)\n", " resized_im, seg_map = MODEL.run(orignal_im)\n",
"\n", "\n",
" vis_segmentation(resized_im, seg_map)\n", " vis_segmentation(resized_im, seg_map)\n",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment