def extract_faces(data_dir): face_detector = MTCNN(device=device, margin=16) face_detector.eval() for image_name in tqdm(os.listdir(data_dir), desc='Extracting faces'): inp_img_path = os.path.join(data_dir, image_name) out_img_path = os.path.join(FACES_DATA_DIR, image_name) if not os.path.exists(out_img_path): image = Image.open(inp_img_path) face_detector(image, save_path=out_img_path)
layers=[3, 4, 6, 3], groups=32, width_per_group=4) # Override the existing FC layer with a new one. self.fc = nn.Linear(2048, num_classes) if checkpoint: self.load_state_dict(checkpoint) # load model - ResNext checkpoint_path = "runs/May12_02-47-20_4497d0b803cd/epc_12.pth" #"models/Apr07_17-35-04_bb90ec5a54cc/model.pt" net = MyResNeXt(torch.load(checkpoint_path)) net.eval() margin = 16 mtcnn = MTCNN(device='cuda', margin=margin) mtcnn.eval() # get data test_imgs_folder = "../dataset/faceforensics_benchmark_images" test_imgs = glob(test_imgs_folder + "/*.png") result_dict = dict() transform = transforms.Compose([ transforms.Resize((160, 160)), transforms.ToTensor(), transforms.Normalize((123.675, 116.28, 103.53), (58.395, 57.12, 57.375)) ]) with torch.no_grad(): for test_img in tqdm(test_imgs): img = Image.open(test_img)