def define_model(is_resnet, is_densenet, is_senet): if is_resnet: original_model = resnet.resnet50(pretrained = True) Encoder = modules.E_resnet(original_model) model = net.model(Encoder, num_features=2048, block_channel = [256, 512, 1024, 2048]) if is_densenet: original_model = densenet.densenet161(pretrained=True) Encoder = modules.E_densenet(original_model) model = net.model(Encoder, num_features=2208, block_channel = [192, 384, 1056, 2208]) if is_senet: original_model = senet.senet154(pretrained='imagenet') Encoder = modules.E_senet(original_model) model = net.model(Encoder, num_features=2048, block_channel = [256, 512, 1024, 2048]) return model
def main(): Encoder = modules.E_resnet(resnet.resnet50(pretrained=True)) N = net.model(Encoder, num_features=2048, block_channel=[256, 512, 1024, 2048]) N = torch.nn.DataParallel(N).cuda() N.load_state_dict(torch.load('./models/N')) N_adv = copy.deepcopy(N) N_adv.load_state_dict(torch.load('./models/N_adv')) cudnn.benchmark = True test_loader = loaddata.getTestingData(8) #test for N_adv(x*) test_N_adv(test_loader, N, N_adv, epsilon=0.05, iteration=10) test_N_adv(test_loader, N, N_adv, epsilon=0.1, iteration=10) test_N_adv(test_loader, N, N_adv, epsilon=0.15, iteration=10) test_N_adv(test_loader, N, N_adv, epsilon=0.2, iteration=10)
def define_model(target): model = None if target is 'resnet': original_model = resnet.resnet50(pretrained=True) encoder = modules.E_resnet(original_model) model = net.model(encoder, num_features=2048, block_channel=[256, 512, 1024, 2048]) elif target is 'densenet': original_model = densenet.densenet161(pretrained=True) encoder = modules.E_densenet(original_model) model = net.model(encoder, num_features=2208, block_channel=[192, 384, 1056, 2208]) elif target is 'senet': original_model = senet.senet154(pretrained='imagenet') encoder = modules.E_senet(original_model) model = net.model(encoder, num_features=2048, block_channel=[256, 512, 1024, 2048]) return model
import torch.nn as nn import torch.nn.parallel import torch.nn.functional from utils import * from options.testopt import _get_test_opt import nyudv2_dataloader from resnet import resnet18 import modules import net args = _get_test_opt TestImgLoader = nyudv2_dataloader.getTestingData_NYUDV2( args.batch_size, args.testlist_path, args.root_path) Encoder = modules.E_resnet(resnet18) if args.backbone in ['resnet50']: model = net.model(Encoder, num_features=2048, block_channel=[256, 512, 1024, 2048], refinenet=args.refinenet) elif args.backbone in ['resnet18', 'resnet34']: model = net.model(Encoder, num_features=512, block_channel=[64, 128, 256, 512], refinenet=args.refinenet) model = nn.DataParallel(model).cuda() if args.loadckpt is not None and args.loadckpt.endswith('.pth.tar'):