| 17 | |
| 18 | class DataProcessor: |
| 19 | def __init__(self, opt): |
| 20 | self.opt = opt |
| 21 | self.fps = opt.fps |
| 22 | self.sampling_rate = opt.sampling_rate |
| 23 | self.input_size = opt.input_size |
| 24 | |
| 25 | self.fa = face_alignment.FaceAlignment(face_alignment.LandmarksType.TWO_D, flip_input=False) |
| 26 | |
| 27 | # wav2vec2 audio preprocessor |
| 28 | self.wav2vec_preprocessor = Wav2Vec2FeatureExtractor.from_pretrained(opt.wav2vec_model_path, local_files_only=True) |
| 29 | |
| 30 | # image transform |
| 31 | self.transform = A.Compose([ |
| 32 | A.Resize(height=opt.input_size, width=opt.input_size, interpolation=cv2.INTER_AREA), |
| 33 | A.Normalize(mean=(0.5,0.5,0.5), std=(0.5,0.5,0.5)), |
| 34 | A_pytorch.ToTensorV2(), |
| 35 | ]) |
| 36 | |
| 37 | @torch.no_grad() |
| 38 | def process_img(self, img:np.ndarray) -> np.ndarray: |