(prediction_file, return_dict)
return predictions
Convert prediction JSON file.
Convert prediction JSON file.
Convert prediction JSON file .
def load_predictions(prediction_file, return_dict):
    """Convert prediction JSON file."""

    predictions = dict()
    predictions['image_ids'] = []
    predictions['annos'] = dict()
    id_set = set([])

    try:
        preds = json.load(open(prediction_file, 'r'))
    except Exception:
        return_dict['error'] = 'Prediction file does not exist or is an invalid JSON file.'
        exit(return_dict['error'])

    for pred in preds:
        if 'image_id' not in pred.keys():
            return_dict['warning'].append('There is an invalid annotation info, \
                likely missing key \'image_id\'.')
            continue
        if 'keypoint_annotations' not in pred.keys():
            return_dict['warning'].append(pred['image_id']+\
                ' does not have key \'keypoint_annotations\'.')
            continue
        image_id = pred['image_id'].split('.')[0]
        if image_id in id_set:
            return_dict['warning'].append(pred['image_id']+\
                ' is duplicated in prediction JSON file.')
        else:
            id_set.add(image_id)
        predictions['image_ids'].append(image_id)
        predictions['annos'][pred['image_id']] = dict()
        predictions['annos'][pred['image_id']]['keypoint_annos'] = pred['keypoint_annotations']

    return predictions
def load_predictions ( prediction_file , return_dict ) : predictions = dict ( ) predictions [ 'image_ids' ] = [ ] predictions [ 'annos' ] = dict ( ) id_set = set ( [ ] ) try : preds = json . load ( open ( prediction_file , 'r' ) ) except Exception : return_dict [ 'error' ] = 'Prediction file does not exist or is an invalid JSON file.' exit ( return_dict [ 'error' ] ) for pred in preds : if 'image_id' not in pred . keys ( ) : return_dict [ 'warning' ] . append ( 'There is an invalid annotation info, \
                likely missing key \'image_id\'.' ) continue if 'keypoint_annotations' not in pred . keys ( ) : return_dict [ 'warning' ] . append ( pred [ 'image_id' ] + ' does not have key \'keypoint_annotations\'.' ) continue image_id = pred [ 'image_id' ] . split ( '.' ) [ 0 ] if image_id in id_set : return_dict [ 'warning' ] . append ( pred [ 'image_id' ] + ' is duplicated in prediction JSON file.' ) else : id_set . add ( image_id ) predictions [ 'image_ids' ] . append ( image_id ) predictions [ 'annos' ] [ pred [ 'image_id' ] ] = dict ( ) predictions [ 'annos' ] [ pred [ 'image_id' ] ] [ 'keypoint_annos' ] = pred [ 'keypoint_annotations' ] return predictions