(self, resFile)
return res
change by ZhengHe
        Load result file and return a result api object.
        :param   resFile (str)     : file name of result file
        :return: res (obj)         : result api object
change by ZhengHe
        Load result file and return a result api object.
        :param   resFile (str)     : file name of result file
        :return: res (obj)         : result api object
change by ZhengHe Load result file and return a result api object . : param resFile ( str ) : file name of result file : return : res ( obj ) : result api object
def loadRes(self, resFile):
        """
        change by ZhengHe
        Load result file and return a result api object.
        :param   resFile (str)     : file name of result file
        :return: res (obj)         : result api object
        """
        res = COCO()
        res.dataset['images'] = [img for img in self.dataset['images']]
        res.dataset['info'] = copy.deepcopy(self.dataset['info'])
        res.dataset['type'] = copy.deepcopy(self.dataset['type'])
        res.dataset['licenses'] = copy.deepcopy(self.dataset['licenses'])

        # str to hex int for image_id
        imgdict = {}
        def get_image_dict(img_name):
            # image_hash = int(int(hashlib.sha256(img_name).hexdigest(), 16) % sys.maxint)
            image_hash = self.image2hash[img_name]
            if image_hash in imgdict:
                assert imgdict[image_hash] == img_name, 'hash colision: {0}: {1}'.format(image_hash, img_name)
            else:
                imgdict[image_hash] = img_name
            image_dict = {"id": image_hash,
                          "width": 0,
                          "height": 0,
                          "file_name": img_name,
                          "license": '',
                          "url": img_name,
                          "date_captured": '',
                          }
            return image_hash


        print ('Loading and preparing results...     ')
        time_t = datetime.datetime.utcnow()
        anns    = json.load(open(resFile))

        assert type(anns) == list, 'results in not an array of objects'

        # annsImgIds = [ann['image_id'] for ann in anns]
        # change by ZhengHe
        annsImgIds = []
        for ann in anns:
            assert ann['image_id'] != '','image_id must have a name'
            assert ann['caption'] != '', 'caption must be a string'

            w = jieba.cut(ann['caption'].strip().replace('。',''), cut_all=False)
            p = ' '.join(w)
            ann['caption'] = p
            ann['image_id'] = get_image_dict(ann['image_id'])
            annsImgIds.append((ann['image_id']))


        assert set(annsImgIds) == (set(annsImgIds) & set(self.getImgIds())), \
               'Results do not correspond to current coco set'
        if 'caption' in anns[0]:
            imgIds = set([img['id'] for img in res.dataset['images']]) & set([ann['image_id'] for ann in anns])
            res.dataset['images'] = [img for img in res.dataset['images'] if img['id'] in imgIds]
            for id, ann in enumerate(anns):
                ann['id'] = id
        elif 'bbox' in anns[0] and not anns[0]['bbox'] == []:
            res.dataset['categories'] = copy.deepcopy(self.dataset['categories'])
            for id, ann in enumerate(anns):
                bb = ann['bbox']
                x1, x2, y1, y2 = [bb[0], bb[0]+bb[2], bb[1], bb[1]+bb[3]]
                ann['segmentation'] = [[x1, y1, x1, y2, x2, y2, x2, y1]]
                ann['area'] = bb[2]*bb[3]
                ann['id'] = id
                ann['iscrowd'] = 0
        elif 'segmentation' in anns[0]:
            res.dataset['categories'] = copy.deepcopy(self.dataset['categories'])
            for id, ann in enumerate(anns):
                ann['area']=sum(ann['segmentation']['counts'][2:-1:2])
                ann['bbox'] = []
                ann['id'] = id
                ann['iscrowd'] = 0
        print( 'DONE (t=%0.2fs)'%((datetime.datetime.utcnow() - time_t).total_seconds()))

        res.dataset['annotations'] = anns
        res.createIndex()
        return res
def loadRes ( self , resFile ) : res = COCO ( ) res . dataset [ 'images' ] = [ img for img in self . dataset [ 'images' ] ] res . dataset [ 'info' ] = copy . deepcopy ( self . dataset [ 'info' ] ) res . dataset [ 'type' ] = copy . deepcopy ( self . dataset [ 'type' ] ) res . dataset [ 'licenses' ] = copy . deepcopy ( self . dataset [ 'licenses' ] ) # str to hex int for image_id imgdict = { } def get_image_dict ( img_name ) : # image_hash = int(int(hashlib.sha256(img_name).hexdigest(), 16) % sys.maxint) image_hash = self . image2hash [ img_name ] if image_hash in imgdict : assert imgdict [ image_hash ] == img_name , 'hash colision: {0}: {1}' . format ( image_hash , img_name ) else : imgdict [ image_hash ] = img_name image_dict = { "id" : image_hash , "width" : 0 , "height" : 0 , "file_name" : img_name , "license" : '' , "url" : img_name , "date_captured" : '' , } return image_hash print ( 'Loading and preparing results...     ' ) time_t = datetime . datetime . utcnow ( ) anns = json . load ( open ( resFile ) ) assert type ( anns ) == list , 'results in not an array of objects' # annsImgIds = [ann['image_id'] for ann in anns] # change by ZhengHe annsImgIds = [ ] for ann in anns : assert ann [ 'image_id' ] != '' , 'image_id must have a name' assert ann [ 'caption' ] != '' , 'caption must be a string' w = jieba . cut ( ann [ 'caption' ] . strip ( ) . replace ( '。',' ' ), c t_all=F a lse) p = ' ' . join ( w ) ann [ 'caption' ] = p ann [ 'image_id' ] = get_image_dict ( ann [ 'image_id' ] ) annsImgIds . append ( ( ann [ 'image_id' ] ) ) assert set ( annsImgIds ) == ( set ( annsImgIds ) & set ( self . getImgIds ( ) ) ) , 'Results do not correspond to current coco set' if 'caption' in anns [ 0 ] : imgIds = set ( [ img [ 'id' ] for img in res . dataset [ 'images' ] ] ) & set ( [ ann [ 'image_id' ] for ann in anns ] ) res . dataset [ 'images' ] = [ img for img in res . dataset [ 'images' ] if img [ 'id' ] in imgIds ] for id , ann in enumerate ( anns ) : ann [ 'id' ] = id elif 'bbox' in anns [ 0 ] and not anns [ 0 ] [ 'bbox' ] == [ ] : res . dataset [ 'categories' ] = copy . deepcopy ( self . dataset [ 'categories' ] ) for id , ann in enumerate ( anns ) : bb = ann [ 'bbox' ] x1 , x2 , y1 , y2 = [ bb [ 0 ] , bb [ 0 ] + bb [ 2 ] , bb [ 1 ] , bb [ 1 ] + bb [ 3 ] ] ann [ 'segmentation' ] = [ [ x1 , y1 , x1 , y2 , x2 , y2 , x2 , y1 ] ] ann [ 'area' ] = bb [ 2 ] * bb [ 3 ] ann [ 'id' ] = id ann [ 'iscrowd' ] = 0 elif 'segmentation' in anns [ 0 ] : res . dataset [ 'categories' ] = copy . deepcopy ( self . dataset [ 'categories' ] ) for id , ann in enumerate ( anns ) : ann [ 'area' ] = sum ( ann [ 'segmentation' ] [ 'counts' ] [ 2 : - 1 : 2 ] ) ann [ 'bbox' ] = [ ] ann [ 'id' ] = id ann [ 'iscrowd' ] = 0 print ( 'DONE (t=%0.2fs)' % ( ( datetime . datetime . utcnow ( ) - time_t ) . total_seconds ( ) ) ) res . dataset [ 'annotations' ] = anns res . createIndex ( ) return res