diff --git a/retired_benchmarks/vision/classification_and_detection/python/pycoco.py b/retired_benchmarks/vision/classification_and_detection/python/pycoco.py index f9d5f2e873..d490ad8a6a 100644 --- a/retired_benchmarks/vision/classification_and_detection/python/pycoco.py +++ b/retired_benchmarks/vision/classification_and_detection/python/pycoco.py @@ -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)) @@ -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: diff --git a/tools/upscale_coco/coco.py b/tools/upscale_coco/coco.py index 11813957ee..75056e7f45 100755 --- a/tools/upscale_coco/coco.py +++ b/tools/upscale_coco/coco.py @@ -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)) @@ -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: diff --git a/vision/classification_and_detection/python/pycoco.py b/vision/classification_and_detection/python/pycoco.py index f9d5f2e873..d490ad8a6a 100644 --- a/vision/classification_and_detection/python/pycoco.py +++ b/vision/classification_and_detection/python/pycoco.py @@ -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)) @@ -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: