facebookarchive / tutorials

Caffe2 Tutorials
Apache License 2.0
124 stars 60 forks source link

caffe2 doesn't support python3? #20

Open shalijiang opened 5 years ago

shalijiang commented 5 years ago

trying to run the MNIST.ipynb tutorial with Python3.7:

one or both of the MNIST lmbd dbs not found!!
Failed to download dataset. Please download it manually from http://download.caffe2.ai/databases/mnist-lmdb.zip
Unzip it and place the two database folders here: /home/shalijiang/caffe2_notebooks/tutorial_data/mnist
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-f2eb48a717a5> in <module>
     42         print("Failed to download dataset. Please download it manually from {}".format(db_url))
     43         print("Unzip it and place the two database folders here: {}".format(data_folder))
---> 44         raise ex
     45 
     46 # Clean up statistics from any old runs

<ipython-input-5-f2eb48a717a5> in <module>
     38     db_url = "http://download.caffe2.ai/databases/mnist-lmdb.zip"
     39     try:
---> 40         DownloadResource(db_url, data_folder)
     41     except Exception as ex:
     42         print("Failed to download dataset. Please download it manually from {}".format(db_url))

<ipython-input-5-f2eb48a717a5> in DownloadResource(url, path)
      2 def DownloadResource(url, path):
      3     '''Downloads resources from s3 by url and unzips them to the provided path'''
----> 4     import requests, zipfile, StringIO
      5 #     import io as StringIO
      6     print("Downloading... {} to {}".format(url, path))

ModuleNotFoundError: No module named 'StringIO'

I can simply change import StringIO to import io as StringIO, then

one or both of the MNIST lmbd dbs not found!!
Downloading... http://download.caffe2.ai/databases/mnist-lmdb.zip to /home/shalijiang/caffe2_notebooks/tutorial_data/mnist
Failed to download dataset. Please download it manually from http://download.caffe2.ai/databases/mnist-lmdb.zip
Unzip it and place the two database folders here: /home/shalijiang/caffe2_notebooks/tutorial_data/mnist
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-d7998938753f> in <module>
     42         print("Failed to download dataset. Please download it manually from {}".format(db_url))
     43         print("Unzip it and place the two database folders here: {}".format(data_folder))
---> 44         raise ex
     45 
     46 # Clean up statistics from any old runs

<ipython-input-6-d7998938753f> in <module>
     38     db_url = "http://download.caffe2.ai/databases/mnist-lmdb.zip"
     39     try:
---> 40         DownloadResource(db_url, data_folder)
     41     except Exception as ex:
     42         print("Failed to download dataset. Please download it manually from {}".format(db_url))

<ipython-input-6-d7998938753f> in DownloadResource(url, path)
      6     print("Downloading... {} to {}".format(url, path))
      7     r = requests.get(url, stream=True)
----> 8     z = zipfile.ZipFile(StringIO.StringIO(r.content))
      9     z.extractall(path)
     10     print("Completed download and extraction.")

TypeError: initial_value must be str or None, not bytes

Seems this can be further fixed by replacing z = zipfile.ZipFile(StringIO.StringIO(r.content)) by z = zipfile.ZipFile(io.BytesIO(r.content))

is this right?