将 MVAD 的标注数据转成 CSV(Youtube Clips 的数据格式)

Preface

目前我正在处理几个 Video Caption 的数据集,一个是 YoutubeClips 数据集。其标注是微软发布的一个 Microsoft Research Video Description Corpus
,安装完成后,会得到一个 CSV 文件,这个文件如下:

这里写图片描述

第一列是视频名称,第二列 Start 是标注的开始帧数,第三列 End 是标注的结束帧数,第七列 Language 是标注的语言,最后一列是标注文字内容。

但是,另一个数据集:MVAD: Montreal Video Annotation Dataset,其标注格式是 srt 格式的文件,形式如下:

这里写图片描述

那么,要想用重复利用训练 YouTubeClips 的代码,就得讲 MVAD 的数据格式转化为 CSV 文件。

这个转化就得用上传说中的 pandas 模块了。我之前没接触到 pandas,这也是第一次使用吧。其实这个模块很方便很简单,我写了一段脚本进行转换,并保存为 CSV 文件,代码如下。

Code

#! encoding:UTF-8

import os
import glob

import cv2

import numpy as np
import pandas as pd

train_videos_path = '/home/ou-lc/chenxp/Downloads/MVAD/train_videos'

train_srt_txt_path = '/home/ou-lc/chenxp/Downloads/M-VAD_txtfiles/srt_files/train_srt'
train_txt_files = glob.glob(train_srt_txt_path + '/*.srt')

video_information = []
for each_train_srt in train_txt_files:
    train_srts = open(each_train_srt, 'r').read().splitlines()

    videos_ID = []
    #videos_Time_Stamp = []; videos_Start = []; videos_End = []
    videos_Language = []
    videos_Descriptions = []
    for idx_srt, video_srt in enumerate(train_srts):
        if idx_srt % 4 == 0:
            videos_ID.append(video_srt)
        #if idx_srt % 4 == 1:
        #    videos_Time_Stamp.append(video_srt)
        if idx_srt % 4 == 2:
            videos_Language.append('English')
            videos_Descriptions.append(video_srt)
    for idx, each_video_name in enumerate(videos_ID):
        video_information.append((each_video_name, videos_Language[idx], videos_Descriptions[idx]))

df = pd.DataFrame(video_information, columns=['VideoID', 'Language', 'Description'])

print df.shape

df.to_csv('convert_MVAD_train.csv', sep=',', encoding='utf-8')

Reference

以上脚本的两处关键代码参考了如下资料:
1. http://stackoverflow.com/questions/16923281/pandas-writing-dataframe-to-csv-file
2. http://stackoverflow.com/questions/19961490/construct-pandas-dataframe-from-list-of-tuples

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值