Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def __init__(self, annotation_file=None):
if not annotation_file is None:
print("loading annotations into memory...")
tic = time.time()
dataset = json.load(open(annotation_file, "r"))
with open(annotation_file, "r") as f:
dataset = json.load(f)
assert (
isinstance(dataset, dict)
), "annotation file format {} not supported".format(type(dataset))
Expand Down Expand Up @@ -363,7 +364,8 @@ def loadRes(self, resFile):
print("Loading and preparing results...")
tic = time.time()
if isinstance(resFile, str): # or type(resFile) == unicode:
anns = json.load(open(resFile))
with open(resFile, "r") as f:
anns = json.load(f)
elif isinstance(resFile, np.ndarray):
anns = self.loadNumpyAnnotations(resFile)
else:
Expand Down
6 changes: 4 additions & 2 deletions tools/upscale_coco/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def __init__(self, annotation_file=None):
if not annotation_file is None:
print("loading annotations into memory...")
tic = time.time()
dataset = json.load(open(annotation_file, "r"))
with open(annotation_file, "r") as f:
dataset = json.load(f)
assert (
isinstance(dataset, dict)
), "annotation file format {} not supported".format(type(dataset))
Expand Down Expand Up @@ -362,7 +363,8 @@ def loadRes(self, resFile):
print("Loading and preparing results...")
tic = time.time()
if isinstance(resFile, str): # or type(resFile) == unicode:
anns = json.load(open(resFile))
with open(resFile, "r") as f:
anns = json.load(f)
elif isinstance(resFile, np.ndarray):
anns = self.loadNumpyAnnotations(resFile)
else:
Expand Down
6 changes: 4 additions & 2 deletions vision/classification_and_detection/python/pycoco.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def __init__(self, annotation_file=None):
if not annotation_file is None:
print("loading annotations into memory...")
tic = time.time()
dataset = json.load(open(annotation_file, "r"))
with open(annotation_file, "r") as f:
dataset = json.load(f)
assert (
isinstance(dataset, dict)
), "annotation file format {} not supported".format(type(dataset))
Expand Down Expand Up @@ -363,7 +364,8 @@ def loadRes(self, resFile):
print("Loading and preparing results...")
tic = time.time()
if isinstance(resFile, str): # or type(resFile) == unicode:
anns = json.load(open(resFile))
with open(resFile, "r") as f:
anns = json.load(f)
elif isinstance(resFile, np.ndarray):
anns = self.loadNumpyAnnotations(resFile)
else:
Expand Down
Loading