-
Notifications
You must be signed in to change notification settings - Fork 191
/
test_video_face_blur_mapper.py
88 lines (74 loc) · 2.73 KB
/
test_video_face_blur_mapper.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import shutil
import unittest
from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.video_face_blur_mapper import VideoFaceBlurMapper
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
class VideoFaceBlurMapperTest(DataJuicerTestCaseBase):
maxDiff = None
data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..',
'data')
vid1_path = os.path.join(data_path, 'video1.mp4')
vid4_path = os.path.join(data_path, 'video4.mp4')
vid5_path = os.path.join(data_path, 'video5.mp4')
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.chk_path = os.path.join(cls.data_path, cls.__name__)
shutil.rmtree(cls.chk_path, ignore_errors=True)
os.makedirs(cls.chk_path)
def _run_helper(self, op, source_list, np=1):
dataset = Dataset.from_list(source_list)
dataset = dataset.map(op.process, num_proc=np)
res_list = dataset.to_list()
for source, res in zip(source_list, res_list):
self.assertEqual(len(source[op.video_key]), len(res[op.video_key]))
# for manual check
for path in res[op.video_key]:
basename = os.path.basename(path)
dst = f'{self.chk_path}/{op.blur_type}:{op.radius}_np:{np}_{basename}'
shutil.copy(path, dst)
def test_gaussian_radius(self):
ds_list = [{
'videos': [self.vid1_path]
}, {
'videos': [self.vid4_path]
}, {
'videos': [self.vid5_path]
}]
op = VideoFaceBlurMapper(blur_type='gaussian', radius=10)
self._run_helper(op, ds_list)
def test_box_radius(self):
ds_list = [{
'videos': [self.vid1_path]
}, {
'videos': [self.vid4_path]
}, {
'videos': [self.vid5_path]
}]
op = VideoFaceBlurMapper(blur_type='box', radius=10)
self._run_helper(op, ds_list)
def test_mean(self):
ds_list = [{
'videos': [self.vid1_path]
}, {
'videos': [self.vid4_path]
}, {
'videos': [self.vid5_path]
}]
op = VideoFaceBlurMapper(blur_type='mean')
self._run_helper(op, ds_list)
def test_gaussian_radius_parallel(self):
import multiprocess as mp
mp.set_start_method('forkserver', force=True)
ds_list = [{
'videos': [self.vid1_path]
}, {
'videos': [self.vid4_path]
}, {
'videos': [self.vid5_path]
}]
op = VideoFaceBlurMapper(blur_type='gaussian', radius=10)
self._run_helper(op, ds_list, np=3)
if __name__ == '__main__':
unittest.main()