示例#1
0
def load_model(opt):
    if opt.pretrained_file != "":
        model = torch.load(opt.pretrained_file)
    else:
        if opt.model_def == 'gazenet':
            model = gazenet.Net(opt)
            if opt.cuda:
                model = model.cuda()
    return model
示例#2
0
def load_model(opt):
    model = gazenet.Net(opt)

    return model.cuda()
示例#3
0
from torchvision import transforms
import matplotlib.pyplot as plt
import matplotlib

parser = opts.optionargparser()
opt = parser.parse_args()

opt.testbatchsize = 16

checkpoint = torch.load(
    './savedmodels/gazenet_gazefollow_softmaxnesterovsgd_70epoch.pth.tar')
print("Loading pretrained model: ")
start_epoch = checkpoint['epoch']
best_err = checkpoint['best_err']

model = gazenet.Net(opt).cuda()
model.load_state_dict(checkpoint['state_dict'])

dataloader = ld.GazeFollow(opt)

images, xis, eye_coords, pred_coords, eyes, names, eyes2, gaze_final = next(
    iter(dataloader.val_loader))

images, xis, eye_coords, pred_coords, gaze_final = images.cuda(), xis.cuda(
), eye_coords.cuda(), pred_coords.cuda(), gaze_final.cuda()

outputs = model.predict(images, xis, eye_coords)

untr = transforms.Compose(
    [transforms.Normalize([0, 0, 0], [1 / (0.229), 1 / (0.224), 1 / (0.225)])])
untr2 = transforms.Compose(
示例#4
0
sys.path.append('./sfd')

parser = opts.optionargparser()
opt = parser.parse_args()

torch.device('cpu')
# checkpoint = torch.load('./savedmodels/adamodels/gazenet_gazefollow_99epoch.pth.tar')
checkpoint = torch.load(
    './savedmodels/gazenet_gazefollow_highcrop_Hope_20epoch.pth.tar',
    map_location=lambda storage, loc: storage)

print("Loading our pretrained gazenet model: ")
start_epoch = checkpoint['epoch']
#best_err = checkpoint['best_prec1']

model = gazenet.Net(opt).cpu()
model.load_state_dict(checkpoint['state_dict'])

imglist = glob.glob('imgs/test/*')
c = 0
for imname in imglist:

    im = io.imread(imname)
    faces, eye_coords, eyes = facedetect.getFaces(im)

    normtransform = transforms.Compose(
        [transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])

    untr = transforms.Compose([
        transforms.Normalize([0, 0, 0],
                             [1 / (0.229), 1 / (0.224), 1 / (0.225)])