From f77873eb6e722fb596327f53f4e2a1f9d4b8c766 Mon Sep 17 00:00:00 2001 From: Yugnaynehc Date: Fri, 14 Apr 2017 21:02:34 +0800 Subject: [PATCH] add support for loading res from memory --- pycocotools/coco.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pycocotools/coco.py b/pycocotools/coco.py index 8d8d4f2..4a0b1a3 100644 --- a/pycocotools/coco.py +++ b/pycocotools/coco.py @@ -272,7 +272,10 @@ def loadRes(self, resFile): print 'Loading and preparing results... ' time_t = datetime.datetime.utcnow() - anns = json.load(open(resFile)) + if type(resFile) == str: + anns = json.load(open(resFile)) + else: + anns = resFile assert type(anns) == list, 'results in not an array of objects' annsImgIds = [ann['image_id'] for ann in anns] assert set(annsImgIds) == (set(annsImgIds) & set(self.getImgIds())), \ @@ -366,4 +369,4 @@ def segToMask( S, h, w ): N = len(s) rr, cc = polygon(np.array(s[1:N:2]), np.array(s[0:N:2])) # (y, x) M[rr, cc] = 1 - return M \ No newline at end of file + return M