assert len(source_set) == 152397 assert len(target_set) == 28978 source_loader = torch.utils.data.DataLoader(source_set, batch_size=args.batch_size, shuffle=args.shuffle, num_workers=args.num_workers) target_loader = torch.utils.data.DataLoader(target_set, batch_size=args.batch_size, shuffle=args.shuffle, num_workers=args.num_workers) if args.model == 'resnet101': netG = ResBase101().cuda() elif args.model == 'resnet50': netG = ResBase50().cuda() else: raise ValueError('Unexpected value of args.model') netF = ResClassifier(class_num=args.class_num, extract=args.extract).cuda() netF.apply(weights_init) def get_L2norm_loss_self_driven(x): l = (x.norm(p=2, dim=1).mean() - args.radius)**2 return args.weight_ring * l def get_cls_loss(pred, gt): cls_loss = F.nll_loss(F.log_softmax(pred), gt) return cls_loss
source_set = VisDAImage(source_root, source_label, train_transform) target_set = VisDAImage(target_root, target_label, train_transform) assert len(source_set) == 152397 assert len(target_set) == 28978 source_loader = torch.utils.data.DataLoader(source_set, batch_size=args.batch_size, shuffle=args.shuffle, num_workers=args.num_workers) target_loader = torch.utils.data.DataLoader(target_set, batch_size=args.batch_size, shuffle=args.shuffle, num_workers=args.num_workers) netG = ResBase50() netF = ResClassifier(class_num=args.class_num, extract=args.extract) netF.apply(weights_init) netG.cuda() netF.cuda() def get_cls_loss(pred, gt): cls_loss = F.nll_loss(F.log_softmax(pred), gt) return cls_loss def get_L2norm_loss_self_driven(x): radius = x.norm(p=2, dim=1).detach() assert radius.requires_grad == False radius = radius + 0.3