Commit 88dd4b1d authored by Ashwin Bharambe's avatar Ashwin Bharambe Committed by Facebook Github Bot

Prepare for python3 compatibility [1]

Summary:
This is a first step towards python3 compatibility. Specifically, it
tackles:

 - `cPickle`: uses six.moves
 - `Queue`: uses six.moves
 - `urllib2`: uses six.moves and changes `urllib2.urlopen` to `urllib.request.urlopen`

Also, fundamentally it changes the types of all config "byte" types to
"string" types. Those configurations aren't un-encoded byte streams but very
specifically ascii (or unicode encoded) strings which are specified and
consumed by human eyes.

Reviewed By: rbgirshick

Differential Revision: D9662024

fbshipit-source-id: b8372f685b57ec4260ae881a2f8bb7967f337b10
parent fd09e37a
This diff is collapsed.
......@@ -26,11 +26,11 @@ from __future__ import print_function
from __future__ import unicode_literals
import copy
import cPickle as pickle
import logging
import numpy as np
import os
import scipy.sparse
from six.moves import cPickle as pickle
# Must happen before importing COCO API (which imports matplotlib)
import detectron.utils.env as envu
......
......@@ -22,11 +22,11 @@
"""Python implementation of the PASCAL VOC devkit's AP evaluation code."""
import cPickle
import logging
import numpy as np
import os
import xml.etree.ElementTree as ET
from six.moves import cPickle
logger = logging.getLogger(__name__)
......
......@@ -44,11 +44,11 @@ from collections import deque
from collections import OrderedDict
import logging
import numpy as np
import Queue
import signal
import threading
import time
import uuid
from six.moves import queue as Queue
from caffe2.python import core, workspace
......
......@@ -28,9 +28,9 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import cPickle as pickle
import cv2
import numpy as np
from six.moves import cPickle as pickle
from caffe2.proto import caffe2_pb2
......
......@@ -22,9 +22,9 @@ from __future__ import unicode_literals
import contextlib
import logging
import Queue
import threading
import traceback
from six.moves import queue as Queue
log = logging.getLogger(__name__)
......
......@@ -20,13 +20,13 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import cPickle as pickle
import hashlib
import logging
import os
import re
import sys
import urllib2
from six.moves import cPickle as pickle
from six.moves import urllib
logger = logging.getLogger(__name__)
......@@ -45,7 +45,9 @@ def cache_url(url_or_file, cache_dir):
path to the cached file. If the argument is not a URL, simply return it as
is.
"""
is_url = re.match(r'^(?:http)s?://', url_or_file, re.IGNORECASE) is not None
is_url = re.match(
r'^(?:http)s?://', url_or_file, re.IGNORECASE
) is not None
if not is_url:
return url_or_file
......@@ -111,7 +113,7 @@ def download_url(
Credit:
https://stackoverflow.com/questions/2028517/python-urllib2-progress-hook
"""
response = urllib2.urlopen(url)
response = urllib.request.urlopen(url)
total_size = response.info().getheader('Content-Length').strip()
total_size = int(total_size)
bytes_so_far = 0
......@@ -140,5 +142,5 @@ def _get_file_md5sum(file_name):
def _get_reference_md5sum(url):
"""By convention the md5 hash for url is stored in url + '.md5sum'."""
url_md5sum = url + '.md5sum'
md5sum = urllib2.urlopen(url_md5sum).read().strip()
md5sum = urllib.request.urlopen(url_md5sum).read().strip()
return md5sum
......@@ -21,12 +21,12 @@ from __future__ import print_function
from __future__ import unicode_literals
from collections import OrderedDict
import cPickle as pickle
import logging
import numpy as np
import os
import pprint
import yaml
from six.moves import cPickle as pickle
from caffe2.python import core
from caffe2.python import workspace
......
......@@ -27,7 +27,7 @@ import os
import yaml
import numpy as np
import subprocess
import cPickle as pickle
from six.moves import cPickle as pickle
from six.moves import shlex_quote
from detectron.core.config import cfg
......
......@@ -9,10 +9,10 @@ from __future__ import print_function
from __future__ import unicode_literals
import argparse
import cPickle as pickle
import numpy as np
import os
import sys
from six.moves import cPickle as pickle
import detectron.datasets.coco_to_cityscapes_id as cs
......
......@@ -24,10 +24,10 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import cPickle as pickle
import numpy as np
import scipy.io as sio
import sys
from six.moves import cPickle as pickle
from detectron.datasets.json_dataset import JsonDataset
......
......@@ -26,10 +26,10 @@ from __future__ import print_function
from __future__ import unicode_literals
import argparse
import cPickle as pickle
import numpy as np
import os
import sys
from six.moves import cPickle as pickle
from caffe.proto import caffe_pb2
from caffe2.proto import caffe2_pb2
......
......@@ -31,10 +31,10 @@ from __future__ import print_function
from __future__ import unicode_literals
import argparse
import cPickle as pickle
import os
import sys
import yaml
from six.moves import cPickle as pickle
from detectron.core.config import cfg
from detectron.datasets import task_evaluation
......
......@@ -23,10 +23,10 @@ from __future__ import print_function
from __future__ import unicode_literals
import argparse
import cPickle as pickle
import cv2
import os
import sys
from six.moves import cPickle as pickle
from detectron.datasets.json_dataset import JsonDataset
import detectron.utils.vis as vis_utils
......
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