|
|
@ -15,7 +15,7 @@ log = logging.getLogger() |
|
|
mean = [0.485, 0.456, 0.406] |
|
|
mean = [0.485, 0.456, 0.406] |
|
|
std = [0.229, 0.224, 0.225] |
|
|
std = [0.229, 0.224, 0.225] |
|
|
normalize_transform = Normalize(mean, std) |
|
|
normalize_transform = Normalize(mean, std) |
|
|
|
|
|
|
|
|
|
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
|
|
|
|
|
|
|
class VideoReader: |
|
|
class VideoReader: |
|
|
"""Helper class for reading one or more frames from a video file.""" |
|
|
"""Helper class for reading one or more frames from a video file.""" |
|
|
@ -201,7 +201,7 @@ class VideoReader: |
|
|
class FaceExtractor: |
|
|
class FaceExtractor: |
|
|
def __init__(self, video_read_fn): |
|
|
def __init__(self, video_read_fn): |
|
|
self.video_read_fn = video_read_fn |
|
|
self.video_read_fn = video_read_fn |
|
|
self.detector = MTCNN(margin=0, thresholds=[0.7, 0.8, 0.8], device="cuda") |
|
|
|
|
|
|
|
|
self.detector = MTCNN(margin=0, thresholds=[0.7, 0.8, 0.8], device=device) |
|
|
|
|
|
|
|
|
def process_videos(self, input_dir, filenames, video_idxs): |
|
|
def process_videos(self, input_dir, filenames, video_idxs): |
|
|
videos_read = [] |
|
|
videos_read = [] |
|
|
@ -306,7 +306,7 @@ def isotropically_resize_image(img, size, interpolation_down=cv2.INTER_AREA, int |
|
|
def dist(p1, p2): |
|
|
def dist(p1, p2): |
|
|
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) |
|
|
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) |
|
|
|
|
|
|
|
|
detector = MTCNN(margin=0, thresholds=(0.7, 0.8, 0.8), device="cuda") |
|
|
|
|
|
|
|
|
detector = MTCNN(margin=0, thresholds=(0.7, 0.8, 0.8), device=device) |
|
|
def predict_on_video(distill, face_extractor, video_path, batch_size, input_size, models, strategy=np.mean, |
|
|
def predict_on_video(distill, face_extractor, video_path, batch_size, input_size, models, strategy=np.mean, |
|
|
apply_compression=False): |
|
|
apply_compression=False): |
|
|
batch_size *= 4 |
|
|
batch_size *= 4 |
|
|
@ -344,7 +344,7 @@ def predict_on_video(distill, face_extractor, video_path, batch_size, input_size |
|
|
else: |
|
|
else: |
|
|
pass |
|
|
pass |
|
|
if n > 0: |
|
|
if n > 0: |
|
|
x = torch.tensor(x, device="cuda").float() |
|
|
|
|
|
|
|
|
x = torch.tensor(x, device=device).float() |
|
|
#e = torch.tensor(e, device="cuda").float() #eye |
|
|
#e = torch.tensor(e, device="cuda").float() #eye |
|
|
# Preprocess the images. |
|
|
# Preprocess the images. |
|
|
x = x.permute((0, 3, 1, 2)) |
|
|
x = x.permute((0, 3, 1, 2)) |
|
|
|