This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_features(iDirName, cnn_model): | |
# get face detector from dlib and initialize the face aligner | |
detector = dlib.get_frontal_face_detector() | |
# open the video file | |
iFramePaths = [os.path.join(iDirName, iFramePath) for iFramePath in os.listdir(iDirName)] | |
# an empty list to hold the results | |
features = [] | |
# process each frame |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import torch | |
def visualize_cam(mask, img): | |
"""Make heatmap from mask and synthesize GradCAM result image using heatmap and img. | |
Args: | |
mask (torch.tensor): mask shape of (1, 1, H, W) and each element has value in range [0, 1] | |
img (torch.tensor): img shape of (1, 3, H, W) and each pixel value is in range [0, 1] | |