# Parse arguments
parser = ArgumentParser(description=('Sample images from the generative component of a '
                                     'cGAN learned on the LFW/LFWcrop dataset.'))
parser.add_argument('-s', '--conditional-sampler', default='fix_random',
                    choices=sampler.conditional_samplers.values(),
                    type=lambda k: sampler.conditional_samplers[k])
parser.add_argument('-e', '--embedding-file')
parser.add_argument('--show-nearest-training', default=False, action='store_true')
parser.add_argument('model_path')
args = parser.parse_args()


m, n = 4, 5
topo_samples, _ = sampler.get_conditional_topo_samples(args.model_path, m, n,
                                                       args.conditional_sampler,
                                                       embedding_file=(args.embedding_file if args.embedding_file is not None
                                                                       else sampler.DEFAULT_EMBEDDING_FILE))

pv = PatchViewer(grid_shape=(m, (n + 1 if args.show_nearest_training else n)),
                 patch_shape=(32,32), is_color=True)

# Optionally load dataset for --show-nearest-training
dataset = None
if args.show_nearest_training:
    model = serial.load(args.model_path)

    # Shape: b * (0 * 1 * c)
    # (topo view)
    dataset = yaml_parse.load(model.dataset_yaml_src)

for i in xrange(topo_samples.shape[0]):
parser.add_argument('-n', type=int, default=1000, help='Number of images to generate')
parser.add_argument('model_path')
parser.add_argument('output_directory')
args = parser.parse_args()


if os.path.exists(args.output_directory):
    print 'Warning: output directory %s exists' % args.output_directory

    if os.path.isfile(args.output_directory):
        raise ValueError("Provided output directory %s is a file" % args.output_directory)
else:
    try:
        os.mkdirs(args.output_directory)
    except AttributeError:
        os.mkdir(args.output_directory)


samples, cond_data = sampler.get_conditional_topo_samples(args.model_path, args.n, 1,
                                                          args.conditional_sampler)

for i, sample in enumerate(samples):
    img = make_image_from_sample(sample)
    path = os.path.join(args.output_directory, '%04i.png' % i)
    img.save(path)
print >> sys.stderr, "Saved %i images to %s." % (args.n, args.output_directory)

np.save(os.path.join(args.output_directory, 'conditional_data'), cond_data)
scipy.io.savemat(os.path.join(args.output_directory, 'conditional_data.mat'), {'x': cond_data})
print >> sys.stderr, 'Saved conditional data matrix.'
Exemplo n.º 3
0
                    '--conditional-sampler',
                    default='fix_random',
                    choices=sampler.conditional_samplers.values(),
                    type=lambda k: sampler.conditional_samplers[k])
parser.add_argument('-e', '--embedding-file')
parser.add_argument('--show-nearest-training',
                    default=False,
                    action='store_true')
parser.add_argument('model_path')
args = parser.parse_args()

m, n = 4, 5
topo_samples, _ = sampler.get_conditional_topo_samples(
    args.model_path,
    m,
    n,
    args.conditional_sampler,
    embedding_file=(args.embedding_file if args.embedding_file is not None else
                    sampler.DEFAULT_EMBEDDING_FILE))

pv = PatchViewer(grid_shape=(m, (n + 1 if args.show_nearest_training else n)),
                 patch_shape=(32, 32),
                 is_color=True)

# Optionally load dataset for --show-nearest-training
dataset = None
if args.show_nearest_training:
    model = serial.load(args.model_path)

    # Shape: b * (0 * 1 * c)
    # (topo view)
Exemplo n.º 4
0
                    help='Number of images to generate')
parser.add_argument('model_path')
parser.add_argument('output_directory')
args = parser.parse_args()

if os.path.exists(args.output_directory):
    print 'Warning: output directory %s exists' % args.output_directory

    if os.path.isfile(args.output_directory):
        raise ValueError("Provided output directory %s is a file" %
                         args.output_directory)
else:
    try:
        os.mkdirs(args.output_directory)
    except AttributeError:
        os.mkdir(args.output_directory)

samples, cond_data = sampler.get_conditional_topo_samples(
    args.model_path, args.n, 1, args.conditional_sampler)

for i, sample in enumerate(samples):
    img = make_image_from_sample(sample)
    path = os.path.join(args.output_directory, '%04i.png' % i)
    img.save(path)
print >> sys.stderr, "Saved %i images to %s." % (args.n, args.output_directory)

np.save(os.path.join(args.output_directory, 'conditional_data'), cond_data)
scipy.io.savemat(os.path.join(args.output_directory, 'conditional_data.mat'),
                 {'x': cond_data})
print >> sys.stderr, 'Saved conditional data matrix.'