Skip to content

Commit

Permalink
Fix loadRes() to work with both Python 2 and 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
waleedka committed May 18, 2017
1 parent 336d2a2 commit f83e955
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions PythonAPI/pycocotools/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,12 @@ def loadRes(self, resFile):

print('Loading and preparing results...')
tic = time.time()
if type(resFile) == str or type(resFile) == unicode:
# Check result type in a way compatible with Python 2 and 3.
try:
is_string = isinstance(resFile, basestring) # Python 2
except NameError:
is_string = isinstance(resFile, str) # Python 3
if is_string:
anns = json.load(open(resFile))
elif type(resFile) == np.ndarray:
anns = self.loadNumpyAnnotations(resFile)
Expand Down Expand Up @@ -425,4 +430,4 @@ def annToMask(self, ann):
"""
rle = self.annToRLE(ann)
m = maskUtils.decode(rle)
return m
return m

0 comments on commit f83e955

Please sign in to comment.