Ejemplo n.º 1
0
def main(args):
    # Load trained model
    model = Inception()
    serializers.load_hdf5(args.model, model)

    if args.gpu >= 0:
        cuda.get_device(args.gpu).use()
        model.to_gpu()

    # Load images
    if 0:
        train, test = datasets.get_cifar10(ndim=3,
                                           withlabel=False,
                                           scale=255.0)
    else:
        train, test = datasets.get_mnist(ndim=3,
                                         rgb_format=True,
                                         scale=255.0,
                                         withlabel=False)

    # Use all 60000 images, unless the number of samples are specified
    ims = np.concatenate((train, test))
    if args.samples > 0:
        ims = ims[:args.samples]

    mean, std = inception_score(model, ims)

    print('Inception score mean:', mean)
    print('Inception score std:', std)
Ejemplo n.º 2
0
 def image_sampler(self):
     iters = int(
         math.ceil(float(self.opt.sample_num) / float(self.opt.batch_size)))
     self.ims = []
     for iter in range(iters):
         sample_z = np.random.normal(0, 1, size=(64, self.opt.z_dimension))
         samples = self.sess.run(self.samples, feed_dict={self.z: sample_z})
         self.ims.append(samples)
     # Load trained model
     ims = np.reshape(self.ims, (-1, 32, 32, 3))
     ims = ims[:self.opt.sample_num].transpose(0, 3, 1, 2)
     ims = ((ims + 1.0) * 127.5).astype(np.uint8)
     ims = ims.astype('f')
     model = Inception()
     serializers.load_hdf5('inception_score.model', model)
     cuda.get_device(0).use()
     model.to_gpu()
     with chainer.no_backprop_mode(), chainer.using_config('train', False):
         mean, std = inception_score(model, ims)
     self.mean.append(mean)
     print('Inception score mean: %4.4f /  %4.4f' % (mean, max(self.mean)))
     print('Inception score std:', std)
     with open('data.txt', 'a', encoding='ascii') as f:
         f.write(str(self.counter))
         f.write(':')
         f.write(str(mean))
         f.write(',  ')
         f.write(str(std))
         f.write('\n')
     return mean, std
Ejemplo n.º 3
0
def main(args):
    # Load trained model
    model = Inception()
    serializers.load_hdf5(args.model, model)

    if args.gpu >= 0:
        cuda.get_device(args.gpu).use()
        model.to_gpu()

    # Load images
    train, test = datasets.get_cifar10(ndim=3, withlabel=False, scale=255.0)

    # Use all 60000 images, unless the number of samples are specified
    ims = np.concatenate((train, test))
    if args.samples > 0:
        ims = ims[:args.samples]

    with chainer.no_backprop_mode(), chainer.using_config('train', False):
        mean, std = inception_score(model, ims)

    print('Inception score mean:', mean)
    print('Inception score std:', std)
Ejemplo n.º 4
0
def main(args):
    outfile = args.outfile

    # Download pretrained TensorFlow model
    download_tf_params()

    # Create empty Chainer inception model
    model = Inception()

    # Update parameters of Chainer model with pretrained TensorFlow model
    set_tf_params(model)

    # TODO(hvy): Test score similarity with the original implementation

    print('Saving ', outfile, '...')
    serializers.save_hdf5(outfile, model)
Ejemplo n.º 5
0
import cupy as xp
import numpy as np
from evaluation import *


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('--gpu', type=int, default=0)
    parser.add_argument('--data', type=str, default='CIFAR')
    return parser.parse_args()


if __name__ == '__main__':
    args = parse_args()
    model = Inception()
    serializers.load_hdf5('metric/inception_score.model', model)
    if args.gpu >= 0:
        cuda.get_device(args.gpu).use()
        model.to_gpu()

    datapath = 'training_data/{}.npy'.format(args.data)
    mean_savepath = 'metric/{}_inception_mean.npy'.format(args.data)
    cov_savepath = 'metric/{}_inception_cov.npy'.format(args.data)

    img = 255 * xp.load(datapath).astype(xp.float32)
    with chainer.using_config('train', False), chainer.using_config(
            'enable_backprop', False):
        mean, cov = get_mean_cov(model, img)

    np.save(mean_savepath, mean)
def load_inception_model():
    infile = "%s/inception_score.model"%os.path.dirname(__file__)
    model = Inception()
    serializers.load_hdf5(infile, model)
    model.to_gpu()
    return model
def load_inception_model():
    infile = "inception_score.model"
    model = Inception()
    serializers.load_hdf5(infile, model)
    model.to_gpu()
    return model
Ejemplo n.º 8
0
def load_inception_model():
    model = Inception()
    serializers.load_hdf5('metric/inception_score.model', model)
    model.to_gpu()
    return model