Skip to content

Instantly share code, notes, and snippets.

View sumon328's full-sized avatar

sumon328

  • Bangladesh
View GitHub Profile
@Justin-Heer
Justin-Heer / extract_features.py
Created August 16, 2020 16:20
extract_features
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
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]