parser.add_argument('--seed', type=float, default=0) args = parser.parse_args() device = torch.device('cuda:' + str(args.gpu) if torch.cuda.is_available() else 'cpu') # Data torch.manual_seed(args.seed) if device == 'cuda': cudnn.benchmark = True torch.cuda.manual_seed(args.seed) print('load data: ', args.dataset) train_loader, test_loader = data_loader.getDataSet(args.dataset, args.batch_size, args.test_batch_size, args.imageSize) # Model print('==> Building model..') net = models.Resnet() net = net.to(device) criterion = nn.CrossEntropyLoss() optimizer = optim.SGD(net.parameters(), lr=args.lr, momentum=0.9, weight_decay=5e-4) # Training
parser.add_argument('--decreasing_lr2', default=[15, 30], nargs='+', help='decreasing strategy') args = parser.parse_args() device = torch.device('cuda:' + str(args.gpu) if torch.cuda.is_available() else 'cpu') torch.manual_seed(args.seed) random.seed(args.seed) if device == 'cuda': cudnn.benchmark = True torch.cuda.manual_seed(args.seed) print('load in-domain data: ',args.dataset_inDomain) train_loader_inDomain, test_loader_inDomain = data_loader.getDataSet(args.dataset_inDomain, args.batch_size, args.test_batch_size, args.imageSize) # Model print('==> Building model..') net = models.SDENet_mnist(layer_depth=6, num_classes=10, dim=64) net = net.to(device) real_label = 0 fake_label = 1 criterion = nn.CrossEntropyLoss() criterion2 = nn.BCELoss() optimizer_F = optim.SGD([ {'params': net.downsampling_layers.parameters()}, {'params': net.drift.parameters()}, {'params': net.fc_layers.parameters()}], lr=args.lr, momentum=0.9, weight_decay=5e-4)