import torch.backends.cudnn as cudnn import torch.optim import torch.utils.data import torchvision.transforms as transforms import torchvision.datasets as datasets H5_address = '/home/lyq/caffe-master/data_gaze/gaze_detection/h5/' Save_model_address = '/disks/disk0/linyuqi/model/gaze_demo/' gaze_model = model.gaze_model() #gaze_model = nn.DataParallel(gaze_model) gaze_model.cuda() img_list = dataset.load_all_h5(H5_address) train_Dataset = dataset.train_gaze_dataset(img_list) test_Dataset = dataset.test_gaze_dataset(img_list) train_loader = torch.utils.data.DataLoader(train_Dataset, batch_size=128, num_workers=6) test_loader = torch.utils.data.DataLoader(test_Dataset, batch_size=128, num_workers=6) l1_loss = nn.SmoothL1Loss().cuda() optimizer = torch.optim.Adam(gaze_model.parameters(), lr=0.001) def train(): gaze_model.train() for i, (image, head_pose, label) in enumerate(train_loader): image = image.squeeze(1)
import torchvision.transforms as transforms import torchvision.datasets as datasets H5_address = '/home/lyq/caffe-master/data_gaze/gaze_detection/h5/' Save_model_address = '/disks/disk0/linyuqi/model/gaze_2eye_AR/' BatchSize = 64 gaze_model = model.gaze_model() gaze_model = nn.DataParallel(gaze_model) gaze_model.cuda() img_list_left, img_list_right = dataset.load_all_h5(H5_address) #print(img_list_left[1]) #print(img_list_right[1]) train_Dataset = dataset.train_gaze_dataset(img_list_left, img_list_right) test_Dataset = dataset.test_gaze_dataset(img_list_left, img_list_right) train_loader = torch.utils.data.DataLoader(train_Dataset, batch_size=BatchSize, num_workers=6) test_loader = torch.utils.data.DataLoader(test_Dataset, batch_size=BatchSize, num_workers=6) l1_loss = nn.SmoothL1Loss().cuda() #l1_loss = nn.MSELoss().cuda() #optimizer = torch.optim.Adam(gaze_model.parameters(),lr=0.01) optimizer = torch.optim.SGD(gaze_model.parameters(), lr=0.001, momentum=0.9) def accuracy_text(result, label):