Coder Social home page Coder Social logo

plat's Introduction

plat (v): plan out or make a map of

Utilities for exploring generative latent spaces as described in the Sampling Generative Networks paper.

Quickstart

Install this library, code supporting a model type, and go.

$ pip install plat
$ plat sample
Saving image file plat_20180401_NoModel_01.png

output image

Sampling Examples

By default, plat does a random sampling. The output file will be automatically generated, or can be given explicitly. To make the results repeatable, you can also specify a random seed.

$ plat sample \
  --seed 1 \
  --outfile examples/random_sample.jpg

output image

The number of rows and columns can be specified. Interpolation is done by specifying the spacing between samples.

$ plat sample \
  --seed 1 \
  --rows 1 --cols 7 \
  --spacing 6 \
  --outfile examples/random_interpolation.jpg

output image

Interpolation can be done across multiple points in two dimensions to create a mine grid (details in paper).

$ plat sample \
  --seed 1 \
  --rows 4 --cols 7 \
  --spacing 3 \
  --outfile examples/random_mine_grid.jpg

output image

There are many more options to explore. When experimenting, it can be useful to use a templated output filename.

$ plat sample \
  --seed 17 \
  --tight \
  --rows 3 --cols 7 \
  --spacing 2 \
  --outfile examples/%DATE%_experiment_s%SEED%_%SEQ%.jpg

output image

Model types

plat comes with access to a growing list of models and model types in its model zoo. Each model type will have separate dependencies.

It's also possible to run plat on new types of models by providing a simple plat interface. There are a few examples and a template to get started. Here's an example of how to use plat sample with a manually specified model interface to generate a (random) mine grid from an iGAN model:

PYTHONPATH=. plat sample \
  --model-interface plat.interface.igan.IganModel \
  --model-file models/shoes_64.dcgan_theano \
  --uniform \
  --rows 4 --cols 10 \
  --tight --spacing 3 \
  --image-size 64 \
  --seed 1

output image

plat's People

Contributors

dribnet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plat's Issues

run error

ec2 g2.2xlarge and p2.xlarge machine

pip install plat:
Successfully installed plat-0.2.2

plat sample --model celeba_64.discgen
Loading DiscGenModel interface from discgen.interface
Loading model celeba_64.discgen

Using gpu device 0: GRID K520 (CNMeM is disabled, cuDNN 4007)
Model loaded.
Building computation graph...
Compiling sampling function...
Traceback (most recent call last):
File "/home/ubuntu/anaconda2/envs/tensorflow/bin/plat", line 11, in
sys.exit(main())
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/plat/bin/platcmd.py", line 12, in main
handler.run()
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/arghandler/base.py", line 295, in run
self._subcommand_lookupargs.cmd
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/plat/bin/sample.py", line 256, in sample
run_with_args(args, dmodel, args.anchor_image, args.save_path, cur_z_step)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/plat/bin/sample.py", line 138, in run_with_args
plat.sampling.grid_from_latents(z, dmodel, args.rows, args.cols, anchor_images, args.tight, args.shoulders, cur_save_path, args, args.batch_size)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/plat/sampling.py", line 108, in grid_from_latents
decoded = dmodel.sample_at(cur_z)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/discgen/interface.py", line 79, in sample_at
latents, samples = self.sampling_function(z_float)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/theano/compile/function_module.py", line 871, in call
storage_map=getattr(self.fn, 'storage_map', None))
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/theano/gof/link.py", line 314, in raise_with_op
reraise(exc_type, exc_value, exc_trace)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/theano/compile/function_module.py", line 859, in call
outputs = self.fn()
ValueError: CorrMM received weight with wrong type.
Apply node that caused the error: CorrMM{(1, 1), (1, 1)}(decoder_convnet_apply_args_0, Subtensor{::, ::, ::int64, ::int64}.0)
Toposort index: 158
Inputs types: [TensorType(float64, 4D), TensorType(float32, 4D)]
Inputs shapes: [(21, 256, 4, 4), (256, 256, 3, 3)]
Inputs strides: [(32768, 128, 32, 8), (9216, 36, -12, -4)]
Inputs values: ['not shown', 'not shown']
Outputs clients: [[Elemwise{Composite{(i0 * (Composite{((((i0 - i1) / i2) * i3) + i4)}(i1, i2, i3, i4, i5) + Abs(Composite{((((i0 - i1) / i2) * i3) + i4)}(i1, i2, i3, i4, i5))))}}[(0, 1)](TensorConstant{(1, 1, 1, 1) of 0.5}, conv1_apply_output, shape_padleft(population_mean), shape_padleft(population_stdev), shape_padleft(batch_norm_scale), shape_padleft(batch_norm_shift))]]

Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer):
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/discgen/interface.py", line 76, in sample_at
self.sampling_function = get_decoder_function(self.model)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/discgen/interface.py", line 39, in get_decoder_function
(-1,) + decoder_convnet.get_dim('input_')))
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/blocks/bricks/base.py", line 371, in call
return self.application.apply(self, *args, **kwargs)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/blocks/bricks/base.py", line 306, in apply
outputs = self.application_function(brick, *args, **kwargs)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/blocks/bricks/sequences.py", line 37, in apply
output = application_method(*pack(child_input))
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/blocks/bricks/base.py", line 371, in call
return self.application.apply(self, *args, **kwargs)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/blocks/bricks/base.py", line 306, in apply
outputs = self.application_function(brick, *args, **kwargs)
File "/home/ubuntu/anaconda2/envs/tensorflow/lib/python2.7/site-packages/blocks/bricks/conv.py", line 144, in apply
self.filter_size))

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

Error when running on Mac

plat sample --model celeba_64.discgen
Loading DiscGenModel interface from discgen.interface
Loading model celeba_64.discgen
Traceback (most recent call last):
File "/Users/saurabhmishra/anaconda/bin/plat", line 11, in
sys.exit(main())
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/plat/bin/platcmd.py", line 12, in main
handler.run()
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/arghandler/base.py", line 295, in run
self._subcommand_lookupargs.cmd
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/plat/bin/sample.py", line 256, in sample
run_with_args(args, dmodel, args.anchor_image, args.save_path, cur_z_step)
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/plat/bin/sample.py", line 67, in run_with_args
dmodel = zoo.load_model(args.model, args.model_file, args.model_type, args.model_interface)
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/plat/zoo.py", line 72, in load_model
return load_model_with_interface(model_file_name, model_interface)
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/plat/zoo.py", line 50, in load_model_with_interface
model = ModelClass(filename=model_file_name)
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/discgen/interface.py", line 60, in init
self.model = Model(load(src).algorithm.cost)
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/blocks/serialization.py", line 277, in load
return p.load()
File "/Users/saurabhmishra/anaconda/lib/python2.7/pickle.py", line 864, in load
dispatchkey
File "/Users/saurabhmishra/anaconda/lib/python2.7/pickle.py", line 902, in load_binpersid
self.append(self.persistent_load(pid))
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/blocks/serialization.py", line 600, in call
components = unmangle_parameter_name(id)
File "/Users/saurabhmishra/anaconda/lib/python2.7/site-packages/blocks/serialization.py", line 633, in _unmangle_parameter_name
return INVERSE_ARRAY_TYPE_MAP[type], context_name, name
KeyError: 'cuda_ndarray'

I am getting this error when I try to run the program on a MacBook Pro. Any solutions for this? I have tried to find online what could be the reason for this but haven't had any success.

Errors in zoo.py

Hello,
I was running the quickstart code and it gave me this error on Python3.6:
โžœ plat plat sample --model celeba_64.discgen Traceback (most recent call last): File "/home/<username>/.local/bin/plat", line 11, in <module> sys.exit(main()) [...] File "/home/<username>/.local/lib/python3.6/site-packages/plat/zoo.py", line 131, in check_model_download result = raw_input("Model {} will be downloaded. Continue? [Y/n]".format(model_name)) NameError: name 'raw_input' is not defined
renaming "raw_input" to "input" fixed the issue.

I also have another problem about the quickstart code: after the download it tries to make an hard link from the /tmp/ and the /home/.../.plat/zoo/ folder, which are in two different devices in my system so the command fails. Manually moving the file does not skip the download the next time the command is run. Is there any way to make the code work without retargeting my /tmp folder?
Thank you in advance.

Problems when running the Quickstart example

On running the third command of the quickstart example, I'm getting the following error:

> plat sample --model celeba_64.discgen
Couldn't import dot_parser, loading of dot files will not be possible.
Model celeba_64.discgen will be downloaded. Continue? [Y/n]y
Downloading celeba_64_v1.0.0.discgen.gz

/tmp/tmpfYWrkQ/celeba_64_v1.0.0.discgen.gz: 100% [=========================] Time: 0:00:10  12.9 MiB/s
Decompressing celeba_64.discgen
Installing celeba_64.discgen
Loading DiscGenModel interface from discgen.interface
==> Failed to load supporting class discgen.interface.DiscGenModel
==> Check that package discgen is installed
(exception was: cannot import name bn)

Besides I'm merely interested in the way z is sampled for the GAN training. Maybe someone could kindly point me to the respective position in the code?

Multiple faces

Hi, great work !

How to apply this to images which includes faces more than 1?

regards.

install error

Hello
when I run plat sample --model celeba_64.discgen
I get this:

Loading DiscGenModel interface from discgen.interface
Loading model celeba_64.discgen
Traceback (most recent call last):
File "/home/piccir/anaconda2/bin/plat", line 11, in
sys.exit(main())
File "/home/piccir/anaconda2/lib/python2.7/site-packages/plat/bin/platcmd.py", line 12, in main
handler.run()
File "/home/piccir/anaconda2/lib/python2.7/site-packages/arghandler/base.py", line 295, in run
self._subcommand_lookupargs.cmd
File "/home/piccir/anaconda2/lib/python2.7/site-packages/plat/bin/sample.py", line 256, in sample
run_with_args(args, dmodel, args.anchor_image, args.save_path, cur_z_step)
File "/home/piccir/anaconda2/lib/python2.7/site-packages/plat/bin/sample.py", line 67, in run_with_args
dmodel = zoo.load_model(args.model, args.model_file, args.model_type, args.model_interface)
File "/home/piccir/anaconda2/lib/python2.7/site-packages/plat/zoo.py", line 72, in load_model
return load_model_with_interface(model_file_name, model_interface)
File "/home/piccir/anaconda2/lib/python2.7/site-packages/plat/zoo.py", line 50, in load_model_with_interface
model = ModelClass(filename=model_file_name)
File "/home/piccir/Documents/Repository/discgen/discgen/interface.py", line 60, in init
self.model = Model(load(src).algorithm.cost)
File "/home/piccir/anaconda2/lib/python2.7/site-packages/blocks/serialization.py", line 277, in load
return p.load()
File "/home/piccir/anaconda2/lib/python2.7/pickle.py", line 864, in load
dispatchkey
File "/home/piccir/anaconda2/lib/python2.7/pickle.py", line 902, in load_binpersid
self.append(self.persistent_load(pid))
File "/home/piccir/anaconda2/lib/python2.7/site-packages/blocks/serialization.py", line 600, in call
components = unmangle_parameter_name(id)
File "/home/piccir/anaconda2/lib/python2.7/site-packages/blocks/serialization.py", line 633, in _unmangle_parameter_name
return INVERSE_ARRAY_TYPE_MAP[type], context_name, name
KeyError: 'cuda_ndarray'

Any clue?
I reinstalled Theano with the version from the other issue

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.