当前位置:   article > 正文

LRS2数据集处理

lrs2数据集

一、数据集获取

LRS2数据集官网:Lip Reading Sentences 2 (LRS2) dataset

 

获取方式:

  1. 根据网站https://www.bbc.co.uk/rd/projects/lip-reading-datasets提示,获取word版数据集申请文件,在文件最后签署使用协议,使用邮箱发送到该网站指定邮箱,等待一两天即可收到带有用户名和密码的邮件。
  2. 点击上图中“Download”链接,使用用户名密码登陆,即可下载数据集。共计50GB左右,下载所需时间较长。
  3. 下载后的文件名称及大小如下图所示:

二、数据集处理

1、文件处理

(1)将分段的压缩包整合成一个tar文件,bash命令如下

cat lrs2_v1_parta* > lrs2_v1.tar

(2)解压tar文件

tar -xvf lrs2_v1.tar

2、解析数据集

代码来源:https://github.com/Rudrabha/Wav2Lip/blob/master/preprocess.py

  1. import sys
  2. if sys.version_info[0] < 3 and sys.version_info[1] < 2:
  3. raise Exception("Must be using >= Python 3.2")
  4. from os import listdir, path
  5. if not path.isfile('face_detection/detection/sfd/s3fd.pth'):
  6. raise FileNotFoundError('Save the s3fd model to face_detection/detection/sfd/s3fd.pth \
  7. before running this script!')
  8. import multiprocessing as mp
  9. from concurrent.futures import ThreadPoolExecutor, as_completed
  10. import numpy as np
  11. import argparse, os, cv2, traceback, subprocess
  12. from tqdm import tqdm
  13. from glob import glob
  14. import audio
  15. from hparams import hparams as hp
  16. import face_detection
  17. parser = argparse.ArgumentParser()
  18. parser.add_argument('--ngpu', help='Number of GPUs across which to run in parallel', default=1, type=int)
  19. parser.add_argument('--batch_size', help='Single GPU Face detection batch size', default=32, type=int)
  20. parser.add_argument("--data_root", help="Root folder of the LRS2 dataset", required=True)
  21. parser.add_argument("--preprocessed_root", help="Root folder of the preprocessed dataset", required=True)
  22. args = parser.parse_args()
  23. fa = [face_detection.FaceAlignment(face_detection.LandmarksType._2D, flip_input=False,
  24. device='cuda:{}'.format(id)) for id in range(args.ngpu)]
  25. template = 'ffmpeg -loglevel panic -y -i {} -strict -2 {}'
  26. # template2 = 'ffmpeg -hide_banner -loglevel panic -threads 1 -y -i {} -async 1 -ac 1 -vn -acodec pcm_s16le -ar 16000 {}'
  27. def process_video_file(vfile, args, gpu_id):
  28. video_stream = cv2.VideoCapture(vfile)
  29. frames = []
  30. while 1:
  31. still_reading, frame = video_stream.read()
  32. if not still_reading:
  33. video_stream.release()
  34. break
  35. frames.append(frame)
  36. vidname = os.path.basename(vfile).split('.')[0]
  37. dirname = vfile.split('/')[-2]
  38. fulldir = path.join(args.preprocessed_root, dirname, vidname)
  39. os.makedirs(fulldir, exist_ok=True)
  40. batches = [frames[i:i + args.batch_size] for i in range(0, len(frames), args.batch_size)]
  41. i = -1
  42. for fb in batches:
  43. preds = fa[gpu_id].get_detections_for_batch(np.asarray(fb))
  44. for j, f in enumerate(preds):
  45. i += 1
  46. if f is None:
  47. continue
  48. x1, y1, x2, y2 = f
  49. cv2.imwrite(path.join(fulldir, '{}.jpg'.format(i)), fb[j][y1:y2, x1:x2])
  50. def process_audio_file(vfile, args):
  51. vidname = os.path.basename(vfile).split('.')[0]
  52. dirname = vfile.split('/')[-2]
  53. fulldir = path.join(args.preprocessed_root, dirname, vidname)
  54. os.makedirs(fulldir, exist_ok=True)
  55. wavpath = path.join(fulldir, 'audio.wav')
  56. command = template.format(vfile, wavpath)
  57. subprocess.call(command, shell=True)
  58. def mp_handler(job):
  59. vfile, args, gpu_id = job
  60. try:
  61. process_video_file(vfile, args, gpu_id)
  62. except KeyboardInterrupt:
  63. exit(0)
  64. except:
  65. traceback.print_exc()
  66. def main(args):
  67. print('Started processing for {} with {} GPUs'.format(args.data_root, args.ngpu))
  68. filelist = glob(path.join(args.data_root, '*/*.mp4'))
  69. jobs = [(vfile, args, i%args.ngpu) for i, vfile in enumerate(filelist)]
  70. p = ThreadPoolExecutor(args.ngpu)
  71. futures = [p.submit(mp_handler, j) for j in jobs]
  72. _ = [r.result() for r in tqdm(as_completed(futures), total=len(futures))]
  73. print('Dumping audios...')
  74. for vfile in tqdm(filelist):
  75. try:
  76. process_audio_file(vfile, args)
  77. except KeyboardInterrupt:
  78. exit(0)
  79. except:
  80. traceback.print_exc()
  81. continue
  82. if __name__ == '__main__':
  83. main(args)
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/380691?site
推荐阅读
相关标签
  

闽ICP备14008679号