Spaces:
Sleeping
Sleeping
File size: 2,544 Bytes
907b7f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import torch
import numpy as np
from lipreading.preprocess import *
from lipreading.dataset import MyDataset, pad_packed_collate
def get_preprocessing_pipelines(modality='video'):
# -- preprocess for the video stream
preprocessing = {}
# -- LRW config
if modality == 'video':
crop_size = (88, 88)
(mean, std) = (0.421, 0.165)
# train :
preprocessing['train'] = Compose([ # 여러 개의 preprocess를 사용할 때 Compose()를 사용한다. preprocess.py에 설정되어 있음
Normalize(0.0,255.0),
RandomCrop(crop_size),
HorizontalFlip(0.5),
Normalize(mean, std) ])
preprocessing['val'] = Compose([
Normalize( 0.0,255.0 ),
CenterCrop(crop_size),
Normalize(mean, std) ])
preprocessing['test'] = preprocessing['val'] # test와 val이 같다
elif modality == 'raw_audio':
preprocessing['train'] = Compose([
AddNoise( noise=np.load('./data/babbleNoise_resample_16K.npy')), # train에만 노이즈를 추가해 준다.
NormalizeUtterance()])
preprocessing['val'] = NormalizeUtterance() # z-score 정규화를 수행
preprocessing['test'] = NormalizeUtterance()
return preprocessing
def get_data_loaders(args):
preprocessing = get_preprocessing_pipelines( args.modality)
# create dataset object for each partition
dsets = {partition: MyDataset(
modality=args.modality,
data_partition=partition,
data_dir=args.data_dir,
label_fp=args.label_path,
annonation_direc=args.annonation_direc,
preprocessing_func=preprocessing[partition],
data_suffix='.npz'
) for partition in ['train', 'val', 'test']}
dset_loaders = {x: torch.utils.data.DataLoader(
dsets[x],
batch_size=args.batch_size,
shuffle=True,
collate_fn=pad_packed_collate,
pin_memory=True,
num_workers=args.workers,
worker_init_fn=np.random.seed(1)) for x in ['train', 'val', 'test']}
return dset_loaders
|