def parse_metadata(self, file):
    file_keys = list(file.keys())
    if ('labelAnnotations' in file_keys):
        label_annotations = file['labelAnnotations']
        file_top_score = [x['score'] for x in label_annotations]
        pick_value = int((len(label_annotations) * 0.3))
        if (pick_value == 0):
            pick_value = 1
        file_top_score_pick = [x['score'] for x in label_annotations[:pick_value]]
        file_top_desc = [x['description'] for x in label_annotations]
        file_top_desc_pick = [x['description'] for x in label_annotations[:pick_value]]
        dog_cat_scores = []
        dog_cat_topics = []
        is_dog_or_cat = []
        for label in label_annotations:
            if ((label['description'] == 'dog') or (label['description'] == 'cat')):
                dog_cat_scores.append(label['score'])
                dog_cat_topics.append(label['topicality'])
                is_dog_or_cat.append(1)
            else:
                is_dog_or_cat.append(0)
    else:
        file_top_score = []
        file_top_desc = []
        dog_cat_scores = []
        dog_cat_topics = []
        is_dog_or_cat = []
        file_top_score_pick = []
        file_top_desc_pick = []
    if ('faceAnnotations' in file_keys):
        file_face = file['faceAnnotations']
        n_faces = len(file_face)
    else:
        n_faces = 0
    if ('textAnnotations' in file_keys):
        text_annotations = file['textAnnotations']
        file_n_text_annotations = len(text_annotations)
        file_len_text = [len(text['description']) for text in text_annotations]
    else:
        file_n_text_annotations = 0
        file_len_text = []
    file_colors = file['imagePropertiesAnnotation']['dominantColors']['colors']
    file_crops = file['cropHintsAnnotation']['cropHints']
    file_color_score = [x['score'] for x in file_colors]
    file_color_pixelfrac = [x['pixelFraction'] for x in file_colors]
    file_color_red = [(x['color']['red'] if ('red' in x['color'].keys()) else 0) for x in file_colors]
    file_color_blue = [(x['color']['blue'] if ('blue' in x['color'].keys()) else 0) for x in file_colors]
    file_color_green = [(x['color']['green'] if ('green' in x['color'].keys()) else 0) for x in file_colors]
    file_crop_conf = np.mean([x['confidence'] for x in file_crops])
    file_crop_x = np.mean([x['boundingPoly']['vertices'][1]['x'] for x in file_crops])
    file_crop_y = np.mean([x['boundingPoly']['vertices'][3]['y'] for x in file_crops])
    if ('importanceFraction' in file_crops[0].keys()):
        file_crop_importance = np.mean([x['importanceFraction'] for x in file_crops])
    else:
        file_crop_importance = 0
    metadata = {'annots_top_desc': ' '.join(file_top_desc), 'annots_top_desc_pick': ' '.join(file_top_desc_pick), 'annots_score_pick_mean': np.mean(file_top_score_pick), 'n_faces': n_faces, 'n_text_annotations': file_n_text_annotations, 'crop_conf': file_crop_conf, 'crop_x': file_crop_x, 'crop_y': file_crop_y, 'crop_importance': file_crop_importance}
    metadata.update(self.get_stats(file_top_score, 'annots_score_normal'))
    metadata.update(self.get_stats(file_color_score, 'color_score'))
    metadata.update(self.get_stats(file_color_pixelfrac, 'color_pixel_score'))
    metadata.update(self.get_stats(file_color_red, 'color_red_score'))
    metadata.update(self.get_stats(file_color_blue, 'color_blue_score'))
    metadata.update(self.get_stats(file_color_green, 'color_green_score'))
    metadata.update(self.get_stats(dog_cat_scores, 'dog_cat_scores'))
    metadata.update(self.get_stats(dog_cat_topics, 'dog_cat_topics'))
    metadata.update(self.get_stats(is_dog_or_cat, 'is_dog_or_cat'))
    metadata.update(self.get_stats(file_len_text, 'len_text'))
    metadata.update({'color_red_score_first': (file_color_red[0] if (len(file_color_red) > 0) else (- 1))})
    metadata.update({'color_blue_score_first': (file_color_blue[0] if (len(file_color_blue) > 0) else (- 1))})
    metadata.update({'color_green_score_first': (file_color_green[0] if (len(file_color_green) > 0) else (- 1))})
    metadata.update({'color_pixel_score_first': (file_color_pixelfrac[0] if (len(file_color_pixelfrac) > 0) else (- 1))})
    metadata.update({'color_score_first': (file_color_score[0] if (len(file_color_score) > 0) else (- 1))})
    metadata.update({'label_score_first': (file_top_score[0] if (len(file_top_score) > 0) else (- 1))})
    return pd.Series(metadata)
def parse_metadata(self, file):
    file_keys = list(file.keys())
    if ('labelAnnotations' in file_keys):
        label_annotations = file['labelAnnotations']
        file_top_score = [x['score'] for x in label_annotations]
        pick_value = int((len(label_annotations) * 0.3))
        if (pick_value == 0):
            pick_value = 1
        file_top_score_pick = [x['score'] for x in label_annotations[:pick_value]]
        file_top_desc = [x['description'] for x in label_annotations]
        file_top_desc_pick = [x['description'] for x in label_annotations[:pick_value]]
        dog_cat_scores = []
        dog_cat_topics = []
        is_dog_or_cat = []
        for label in label_annotations:
            if ((label['description'] == 'dog') or (label['description'] == 'cat')):
                dog_cat_scores.append(label['score'])
                dog_cat_topics.append(label['topicality'])
                is_dog_or_cat.append(1)
            else:
                is_dog_or_cat.append(0)
    else:
        file_top_score = []
        file_top_desc = []
        dog_cat_scores = []
        dog_cat_topics = []
        is_dog_or_cat = []
        file_top_score_pick = []
        file_top_desc_pick = []
    if ('faceAnnotations' in file_keys):
        file_face = file['faceAnnotations']
        n_faces = len(file_face)
    else:
        n_faces = 0
    if ('textAnnotations' in file_keys):
        text_annotations = file['textAnnotations']
        file_n_text_annotations = len(text_annotations)
        file_len_text = [len(text['description']) for text in text_annotations]
    else:
        file_n_text_annotations = 0
        file_len_text = []
    file_colors = file['imagePropertiesAnnotation']['dominantColors']['colors']
    file_crops = file['cropHintsAnnotation']['cropHints']
    file_color_score = [x['score'] for x in file_colors]
    file_color_pixelfrac = [x['pixelFraction'] for x in file_colors]
    file_color_red = [(x['color']['red'] if ('red' in x['color'].keys()) else 0) for x in file_colors]
    file_color_blue = [(x['color']['blue'] if ('blue' in x['color'].keys()) else 0) for x in file_colors]
    file_color_green = [(x['color']['green'] if ('green' in x['color'].keys()) else 0) for x in file_colors]
    file_crop_conf = np.mean([x['confidence'] for x in file_crops])
    file_crop_x = np.mean([x['boundingPoly']['vertices'][1]['x'] for x in file_crops])
    file_crop_y = np.mean([x['boundingPoly']['vertices'][3]['y'] for x in file_crops])
    if ('importanceFraction' in file_crops[0].keys()):
        file_crop_importance = np.mean([x['importanceFraction'] for x in file_crops])
    else:
        file_crop_importance = 0
    metadata = {'annots_top_desc': ' '.join(file_top_desc), 'annots_top_desc_pick': ' '.join(file_top_desc_pick), 'annots_score_pick_mean': np.mean(file_top_score_pick), 'n_faces': n_faces, 'n_text_annotations': file_n_text_annotations, 'crop_conf': file_crop_conf, 'crop_x': file_crop_x, 'crop_y': file_crop_y, 'crop_importance': file_crop_importance}
    metadata.update(self.get_stats(file_top_score, 'annots_score_normal'))
    metadata.update(self.get_stats(file_color_score, 'color_score'))
    metadata.update(self.get_stats(file_color_pixelfrac, 'color_pixel_score'))
    metadata.update(self.get_stats(file_color_red, 'color_red_score'))
    metadata.update(self.get_stats(file_color_blue, 'color_blue_score'))
    metadata.update(self.get_stats(file_color_green, 'color_green_score'))
    metadata.update(self.get_stats(dog_cat_scores, 'dog_cat_scores'))
    metadata.update(self.get_stats(dog_cat_topics, 'dog_cat_topics'))
    metadata.update(self.get_stats(is_dog_or_cat, 'is_dog_or_cat'))
    metadata.update(self.get_stats(file_len_text, 'len_text'))
    metadata.update({'color_red_score_first': (file_color_red[0] if (len(file_color_red) > 0) else (- 1))})
    metadata.update({'color_blue_score_first': (file_color_blue[0] if (len(file_color_blue) > 0) else (- 1))})
    metadata.update({'color_green_score_first': (file_color_green[0] if (len(file_color_green) > 0) else (- 1))})
    metadata.update({'color_pixel_score_first': (file_color_pixelfrac[0] if (len(file_color_pixelfrac) > 0) else (- 1))})
    metadata.update({'color_score_first': (file_color_score[0] if (len(file_color_score) > 0) else (- 1))})
    metadata.update({'label_score_first': (file_top_score[0] if (len(file_top_score) > 0) else (- 1))})
    return pd.Series(metadata)