ajbrock / BigGAN-PyTorch

The author's officially unofficial PyTorch BigGAN implementation.
MIT License
2.86k stars 475 forks source link

How to understand the result given by discriminator? #54

Open yqtianust opened 4 years ago

yqtianust commented 4 years ago

Hi, I want to use the discriminator alone.

Following is my code:

import torch
from BigGAN import Discriminator
import utils
from utils import Distribution

def load():
    path ='pre-trained/138k/'
    d_state_dict = torch.load(path + 'D.pth')
    D = Discriminator(D_ch=96, skip_init=True)
    D.load_state_dict(d_state_dict)
    return D

if __name__ == '__main__':
    D = load()
    D.eval()
    D.cuda()
    x = ... //x is an image
    x = x.to('cuda')
    y_ = Distribution(torch.zeros(1, requires_grad=False))
    y_.init_distribution('categorical', num_categories=1000)
    y_ = y_.to('cuda', torch.int64, non_blocking=False, copy=False)
    y_.sample_()
    print(D(x, y_[:1]))

I have three questions:

  1. Is my code correct? Especially the preparation of y_.
  2. How to preprocess x? I use imagenet val 2012.
  3. How to understand the output of D? I find the value could be positive or negative, I am wondering to know which region means Discriminator think the input is fake/real?

Thanks for your time.

smallcube commented 4 years ago

Same question.