transforms.Resize((299, 299)), transforms.ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ]) import glob pictures = glob.glob('/root/picture/*.png') pictures = [Image.open(picture).convert('RGB') for picture in pictures] pictures = [transform(face) for face in pictures] real_faces = [transform(face) for face in real_faces] fake_faces = [transform(face) for face in fake_faces] lxr_net = lxrEfficientNet.from_name('efficientnet-b4', override_params={'num_classes': 2}) lxr_net = MyModel(lxr_net).cuda().eval() lxr_net.load_state_dict(torch.load('/root/data/wzy/new_mtcnn_lxr.pth')) online_perforance = {} with torch.no_grad(): for num_fake, num_real, num_picture in [[12, 0, 0], [9, 0, 3], [6, 0, 6], [3, 0, 9]]: fake_linespace_num = np.linspace(start=0, stop=len(fake_faces) - 1, num=num_fake, dtype=int) real_linespace_num = np.linspace(start=0, stop=len(real_faces) - 1, num=num_real, dtype=int) picture_linespace_num = np.linspace(start=0,
import torch from lxrlocker.kagglefile.kaggle_lxr import EfficientNet, MyModel net = EfficientNet.from_name('efficientnet-b4', override_params={'num_classes': 2}) net = MyModel(net) weight = {} for key, value in torch.load('/root/data/wzy/checkpoint/efficient-all-frame-new/6.pth').items(): if '_fc' in key: fc_key = key.replace('_fc', 'last_linear') weight[fc_key] = value key = 'backbone.' + key print(key) weight[key] = value # net.load_state_dict(weight) # torch.save(net.state_dict(), "/root/data/wzy/lxrlocker/efficient-Acc0.875-All-Frame-45part-epoch-6.pth")
import cv2 from tqdm import tqdm import os import random from model.efficientnet.model import EfficientNet from torch.nn import functional as F random.seed(0) os.environ["CUDA_VISIBLE_DEVICES"] = "0" from lxrlocker.kagglefile.kaggle_lxr import MyModel, EfficientNet as lxrEfficientNet wzy_net = EfficientNet.from_name('efficientnet-b4', override_params={'num_classes': 2}).cuda().eval() wzy_net.load_state_dict(torch.load('/root/data/wzy/checkpoint/efficient-video/14.pth')) lxr_net = lxrEfficientNet.from_name('efficientnet-b4', override_params={'num_classes': 2}) lxr_net = MyModel(lxr_net).cuda().eval() lxr_net.load_state_dict(torch.load('/root/data/wzy/statistic/new_50partpai_tracking2_resize.pth')) from facenet_pytorch import MTCNN import numpy as np class FastMTCNN(object): def __init__(self, *args, **kwargs): self.mtcnn = MTCNN(*args, **kwargs) def __call__(self, frame): boxes, scores = self.mtcnn.detect([frame]) boxes, scores = boxes[0], scores[0] new_boxes = [] for score_index, face_score in enumerate(scores):
print('==> Preparing data..') BATCH_SIZE = 32 EPOCH = 20 INTERVAL = 200 model_name = 'efficient-all-frame-new' save_path = join("/root/data/wzy/checkpoint", model_name) train_dataloader, test_dataloader = get_dataloader(BATCH_SIZE) print('==> Building model..') net = EfficientNet.from_name('efficientnet-b4', override_params={ 'num_classes': 2 }).eval() net = MyModel(net).cuda() net.load_state_dict( torch.load( '/root/data/wzy/lxrlocker/scale2models_lxr/45partmtcnnenhance.pth')) wzy_net = wzyEfficient.from_name('efficientnet-b4', override_params={ 'num_classes': 2 }).cuda() # model_dict = wzy_net.state_dict() # # weight = {} # for key, value in torch.load('/root/data/wzy/lxrlocker/scale2models_lxr/new_45partpai_tracking2_resize.pth').items(): # key = key.replace('backbone.', '') # if '_fc' in key: # continue # key = key.replace('last_linear', '_fc')