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

import sys

if sys.version_info[0] < 3 and sys.version_info[1] < 2:
	raise Exception("Must be using >= Python 3.2")

from os import listdir, path

if not path.isfile('face_detection/detection/sfd/s3fd.pth'):
	raise FileNotFoundError('Save the s3fd model to face_detection/detection/sfd/s3fd.pth \
							before running this script!')

import multiprocessing as mp
from concurrent.futures import ThreadPoolExecutor, as_completed
import numpy as np
import argparse, os, cv2, traceback, subprocess
from tqdm import tqdm
from glob import glob
import audio
from hparams import hparams as hp

import face_detection

parser = argparse.ArgumentParser()

parser.add_argument('--ngpu', help='Number of GPUs across which to run in parallel', default=1, type=int)
parser.add_argument('--batch_size', help='Single GPU Face detection batch size', default=32, type=int)
parser.add_argument("--data_root", help="Root folder of the LRS2 dataset", required=True)
parser.add_argument("--preprocessed_root", help="Root folder of the preprocessed dataset", required=True)

args = parser.parse_args()

fa = [face_detection.FaceAlignment(face_detection.LandmarksType._2D, flip_input=False, 
									device='cuda:{}'.format(id)) for id in range(args.ngpu)]

template = 'ffmpeg -loglevel panic -y -i {} -strict -2 {}'
# template2 = 'ffmpeg -hide_banner -loglevel panic -threads 1 -y -i {} -async 1 -ac 1 -vn -acodec pcm_s16le -ar 16000 {}'

def process_video_file(vfile, args, gpu_id):
	video_stream = cv2.VideoCapture(vfile)
	
	frames = []
	while 1:
		still_reading, frame = video_stream.read()
		if not still_reading:
			video_stream.release()
			break
		frames.append(frame)
	
	vidname = os.path.basename(vfile).split('.')[0]
	dirname = vfile.split('/')[-2]

	fulldir = path.join(args.preprocessed_root, dirname, vidname)
	os.makedirs(fulldir, exist_ok=True)

	batches = [frames[i:i + args.batch_size] for i in range(0, len(frames), args.batch_size)]

	i = -1
	for fb in batches:
		preds = fa[gpu_id].get_detections_for_batch(np.asarray(fb))

		for j, f in enumerate(preds):
			i += 1
			if f is None:
				continue

			x1, y1, x2, y2 = f
			cv2.imwrite(path.join(fulldir, '{}.jpg'.format(i)), fb[j][y1:y2, x1:x2])

def process_audio_file(vfile, args):
	vidname = os.path.basename(vfile).split('.')[0]
	dirname = vfile.split('/')[-2]

	fulldir = path.join(args.preprocessed_root, dirname, vidname)
	os.makedirs(fulldir, exist_ok=True)

	wavpath = path.join(fulldir, 'audio.wav')

	command = template.format(vfile, wavpath)
	subprocess.call(command, shell=True)

	
def mp_handler(job):
	vfile, args, gpu_id = job
	try:
		process_video_file(vfile, args, gpu_id)
	except KeyboardInterrupt:
		exit(0)
	except:
		traceback.print_exc()
		
def main(args):
	print('Started processing for {} with {} GPUs'.format(args.data_root, args.ngpu))

	filelist = glob(path.join(args.data_root, '*/*.mp4'))

	jobs = [(vfile, args, i%args.ngpu) for i, vfile in enumerate(filelist)]
	p = ThreadPoolExecutor(args.ngpu)
	futures = [p.submit(mp_handler, j) for j in jobs]
	_ = [r.result() for r in tqdm(as_completed(futures), total=len(futures))]

	print('Dumping audios...')

	for vfile in tqdm(filelist):
		try:
			process_audio_file(vfile, args)
		except KeyboardInterrupt:
			exit(0)
		except:
			traceback.print_exc()
			continue

if __name__ == '__main__':
	main(args)
  • 4
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 20
    评论
LRS2模型是一个用于语音到文本转换的深度学习模型,它由多个卷积神经网络和循环神经网络组成。如果您想自定义训练LRS2模型,您需要进行以下步骤: 1. 数据收集:您需要收集大量的语音数据,并为每个语音文件创建相应的文字注释,以便训练模型。您可以使用开源的语音数据集,如LibriSpeech或Mozilla Common Voice,或者自己创建数据集。 2. 数据预处理:在训练LRS2模型之前,您需要对数据进行预处理,以便模型可以正确地学习。这包括将语音文件转换为数字表示形式,例如MFCC或Mel-spectrogram,并将注释转换为标签序列。 3. 构建模型:您需要使用深度学习框架(例如TensorFlow或PyTorch)构建LRS2模型。该模型可以包括卷积神经网络(用于提取语音特征)和循环神经网络(用于学习序列模式)等组件。您可以使用现有的模型架构,也可以根据自己的需求设计自己的模型。 4. 训练模型:一旦您构建了LRS2模型,您需要使用收集的数据对其进行训练。训练期间,您需要定义损失函数和优化器,并使用反向传播算法更新模型参数。您还需要选择正确的超参数(例如学习率和批量大小)以获得最佳性能。 5. 模型评估:在训练完成后,您需要对模型进行评估,以确定其性能。您可以使用测试数据集来评估模型的准确性,并使用不同的指标(例如WER和CER)来度量其性能。 6. 模型部署:一旦您满意LRS2模型的性能,您可以将其部署到生产环境中。这可以涉及将模型打包为API或Web服务,并将其集成到您的应用程序中。 需要注意的是,自定义训练LRS2模型需要大量的时间、计算资源和专业知识。如果您没有足够的经验,最好从现有的模型和数据集开始,并逐步调整它们以满足自己的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值