def get_nb_caption_per_img(n, selected_captions):
"""
Get image id from audio caption file names that were selected by their speakers
Choose images that have at least n captions per image
----------
n : int,
desired number of caption per image
selected_captions : list of string,
list of caption file names selected by their speakers
"""
counter_nb_caption=Counter()
for cap in selected_captions:
#get image id
ImgID = cap.split('_')[-0]
# add a count
counter_nb_caption[ImgID]+=1
#choose img_id that have a count of n
d=dict((k, v) for k, v in counter_nb_caption.items() if v == n)
ImgID_selected=d.keys()
return(ImgID_selected)
评论列表
文章目录