Example #1
0
def get_model(model_name, z_dim, configs=None):
    if model_name == 'dc':
        D = GoodDiscriminator()
        G = GoodGenerator()
    elif model_name == 'dcBN':
        D = GoodDiscriminatorbn()
        G = GoodGenerator()
    elif model_name == 'dcD':
        D = GoodDiscriminatord()
        G = GoodGenerator()
    elif model_name == 'DCGAN':
        D = DC_discriminator()
        G = DC_generator(z_dim=z_dim)
    elif model_name == 'Resnet32':
        D = ResNet32Discriminator(n_in=3, num_filters=128, batchnorm=True)
        G = ResNet32Generator(z_dim=z_dim, num_filters=128, batchnorm=True)
    elif model_name == 'Resnet':
        D = ResNetDiscriminator(in_channel=configs['image_channel'],
                                insize=configs['image_size'],
                                num_filters=configs['feature_num'],
                                batchnorm=configs['batchnorm_d'])
        G = ResNetGenerator(z_dim=z_dim,
                            outsize=configs['image_size'],
                            num_filters=configs['feature_num'],
                            batchnorm=configs['batchnorm_g'])
    elif model_name == 'ResnetWBN':
        D = ResNet32Discriminator(n_in=3, num_filters=128, batchnorm=False)
        G = ResNet32Generator(z_dim=z_dim, num_filters=128, batchnorm=True)
    elif model_name == 'DCGAN-WBN':
        D = DC_discriminatorW()
        G = DC_generator(z_dim=z_dim)
    elif model_name == 'dcSN':
        D = GoodSNDiscriminator()
        G = GoodGenerator()
    elif model_name == 'mnist':
        D = dc_D()
        G = dc_G(z_dim=z_dim)
    elif model_name == 'dc32':
        D = dcD32()
        G = dcG32(z_dim=z_dim)
    elif model_name == 'DCGANs':
        D = DCGAN_D(insize=configs['image_size'],
                    channel_num=configs['image_channel'],
                    feature_num=configs['feature_num'],
                    n_extra_layers=configs['n_extra_layers'])
        G = DCGAN_G(outsize=configs['image_size'],
                    z_dim=z_dim,
                    nc=configs['image_channel'],
                    feature_num=configs['feature_num'],
                    n_extra_layers=configs['n_extra_layers'])
    else:
        print('No matching result of :')
    print(model_name)
    return D, G
 config = vars(parser.parse_args())
 print(config)
 print('numpy calculation')
 device = torch.device('cuda:0')
 model = config['model']
 z_dim = config['z_dim']
 if model == 'dc':
     G = GoodGenerator()
 elif model == 'ResGAN':
     G = ResNet32Generator(z_dim=z_dim, num_filters=128, batchnorm=True)
 elif model == 'DCGAN':
     G = DC_generator(z_dim=z_dim)
 elif model == 'mnist':
     G = dc_G(z_dim=z_dim)
 elif model == 'dc32':
     G = dcG32(z_dim=z_dim)
 else:
     raise ValueError('No matching generator for %s' % model)
 G.to(device)
 G.eval()
 evalor = evalor(G=G,
                 z_dim=z_dim,
                 model_dir=config['model_dir'],
                 device=device,
                 log_path=config['logdir'],
                 dim=config['dim'])
 evalor.eval_metrics(begin=config['begin'],
                     end=config['end'],
                     step=config['step'],
                     is_flag=config['eval_is'],
                     fid_flag=config['eval_fid'],