Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Chainer ui v0.3 and imagereport

1,473 views

Published on

a new feature of ChainerUI v0.3 and ImageReport extension

Published in: Technology
  • Be the first to comment

Chainer ui v0.3 and imagereport

  1. 1. Jun. 9th, 2018 @Preferred Networks ChainerUI v0.3 and ImageReport
  2. 2. ChainerUI - mission - Provide useful user interface for Chainer users!
  3. 3. Basic information - github: https://github.com/chainer/chainerui - doc: https://docs.chainer.org/en/stable/ - MIT license - latest: v0.2.0 v0.3.0 (today!) - announce: - JP: https://research.preferred.jp/2017/12/chainerui-release/ - EN: https://preferredresearch.jp/2017/12/20/chainerui-release/
  4. 4. Getting Started Official document: http://chainerui.readthedocs.io/en/latest/getstart.html (JP) Tutorial by KIKAGAKU: https://qiita.com/yoshizaki_kkgk/items/2e4021c614529ab 9ba7b Thank you!
  5. 5. Quick start $ pip install chainerui $ chainerui db create $ chainerui db upgrade $ chainerui project create -d /path/to/results $ chainerui server → Demo! place to “log” file LogReport extension
  6. 6. Quick upgrade (to v0.3) $ # stop chainerui server $ pip install -U chainerui $ chainerui db upgrade $ chainerui server
  7. 7. What’s new, v0.3 - sampled log - more useful result table - performance tuning etc... - https://www.slideshare.net/pfi/chainer-ui-v02-v03 - https://github.com/chainer/chainerui/releases/tag/v0.3.0 → Let’s see!
  8. 8. Image API - ImageReport extension (v0.3~) - Experimental feature - API is not stable - only basic fucntion - no link to image page - /projects/{:project_id}/results/{:result_id}/images
  9. 9. examples/dcgan Example: DCGAN def out_generated_image(gen, dis, rows, cols, seed, dst): @chainer.training.make_extension() def make_image(trainer): np.random.seed(seed) n_images = rows * cols xp = gen.xp z = Variable(xp.asarray(gen.make_hidden(n_images))) with chainer.using_config('train', False): x = gen(z) x = chainer.backends.cuda.to_cpu(x.data) np.random.seed() x = np.asarray(np.clip(x * 255, 0.0, 255.0), dtype=np.uint8) _, _, H, W = x.shape x = x.reshape((rows, cols, 3, H, W)) x = x.transpose(0, 3, 1, 4, 2) x = x.reshape((rows * H, cols * W, 3)) preview_dir = '{}/preview'.format(dst) preview_path = preview_dir + '/image{:0>8}.png'.format(trainer.updater.iteration) if not os.path.exists(preview_dir): os.makedirs(preview_dir) Image.fromarray(x).save(preview_path) return make_image def main(): # ...snip trainer = training.Trainer( updater, (args.epoch, 'epoch'), out=args.out) trainer.extend( out_generated_image( gen, dis, 10, 10, args.seed, args.out), trigger=snapshot_interval) train_dcgan.py visualize.py
  10. 10. Example: DCGAN def out_generated_image(gen, dis, rows, cols, seed): @chainer.training.make_extension() def make_image(trainer): np.random.seed(seed) n_images = rows * cols xp = gen.xp z = Variable(xp.asarray(gen.make_hidden(n_images))) with chainer.using_config('train', False): x = gen(z) x = chainer.backends.cuda.to_cpu(x.data) np.random.seed() x = np.asarray(np.clip(x * 255, 0.0, 255.0), dtype=np.uint8) _, _, H, W = x.shape x = x.reshape((rows, cols, 3, H, W)) x = x.transpose(0, 3, 1, 4, 2) x = x.reshape((rows * H, cols * W, 3)) preview_dir = '{}/preview'.format(dst) preview_path = preview_dir + '/image{:0>8}.png'.format(trainer.updater.iteration) if not os.path.exists(preview_dir): os.makedirs(preview_dir) Image.fromarray(x).save(preview_path) return make_image def main(): # ...snip trainer = training.Trainer( updater, (args.epoch, 'epoch'), out=args.out) trainer.extend( out_generated_image( gen, dis, 10, 10, args.seed, args.out), trigger=snapshot_interval) chainerui.summary.image( x, row=rows) visualizer = out_generated_image(gen, dis, 10, 10, args.seed) trainer.extend(chainerui.extensions.ImageReport( trigger=(1, 'epoch'), image_generator=visualizer))
  11. 11. Web view Example: DCGAN
  12. 12. Example: VAE (MNIST) # Run the training trainer.run() # Visualize the results def save_images(x, filename): # ...snip model.to_cpu() train_ind = [1, 3, 5, 10, 2, 0, 13, 15, 17] x = chainer.Variable(np.asarray(train[train_ind])) with chainer.using_config('train', False), chainer.no_backprop_mode(): x1 = model(x) save_images(x.data, os.path.join(args.out, 'train')) save_images(x1.data, os.path.join(args.out, 'train_reconstructed')) test_ind = [3, 2, 1, 18, 4, 8, 11, 17, 61] x = chainer.Variable(np.asarray(test[test_ind])) with chainer.using_config('train', False), chainer.no_backprop_mode(): x1 = model(x) save_images(x.data, os.path.join(args.out, 'test')) save_images(x1.data, os.path.join(args.out, 'test_reconstructed')) # draw images from randomly sampled z z = chainer.Variable( np.random.normal(0, 1, (9, args.dimz)).astype(np.float32)) x = model.decode(z) save_images(x.data, os.path.join(args.out, 'sampled')) examples/vae train_vae.py
  13. 13. Example: VAE (MNIST) # Run the training trainer.run() # Visualize the results def save_images(x, filename): # ...snip model.to_cpu() train_ind = [1, 3, 5, 10, 2, 0, 13, 15, 17] x = chainer.Variable(np.asarray(train[train_ind])) with chainer.using_config('train', False), chainer.no_backprop_mode(): x1 = model(x) save_images(x.data, os.path.join(args.out, 'train')) save_images(x1.data, os.path.join(args.out, 'train_reconstructed')) test_ind = [3, 2, 1, 18, 4, 8, 11, 17, 61] x = chainer.Variable(np.asarray(test[test_ind])) with chainer.using_config('train', False), chainer.no_backprop_mode(): x1 = model(x) save_images(x.data, os.path.join(args.out, 'test')) save_images(x1.data, os.path.join(args.out, 'test_reconstructed')) # draw images from randomly sampled z z = chainer.Variable( np.random.normal(0, 1, (9, args.dimz)).astype(np.float32)) x = model.decode(z) save_images(x.data, os.path.join(args.out, 'sampled')) def visualize(trainer): train_ind = [1, 3, 5, 10, 2, 0, 13, 15, 17] x = chainer.Variable(np.asarray(train[train_ind])) with chainer.using_config('train', False), chainer.no_backprop_mode(): x1 = model(x) def convert(x): return x.reshape(9, 28, 28).transpose(0, 2, 1) summary.image(convert(x), name='train', row=3) summary.image(convert(x1), name='train_reconstructed', row=3) test_ind = [3, 2, 1, 18, 4, 8, 11, 17, 61] x = chainer.Variable(np.asarray(test[test_ind])) with chainer.using_config('train', False), chainer.no_backprop_mode(): x1 = model(x) summary.image(convert(x), name='test', row=3) summary.image(convert(x1), name='test_reconstructed', row=3) # draw images from randomly sampled z z = chainer.Variable( np.random.normal(0, 1, (9, args.dimz)).astype(np.float32)) x = model.decode(z) summary.image(convert(x), name='sampled', row=3) trainer.extend(ImageReport(image_generator=visualize)) # Run the training trainer.run()
  14. 14. Example: VAE (MNIST)
  15. 15. examples/pix2pix Example: pix2pix def out_image(updater, enc, dec, rows, cols, seed, dst): @chainer.training.make_extension() def make_image(trainer): # ...snip def save_image(x, name, mode=None): # ...snip x = np.asarray(np.clip(gen_all * 128 + 128, 0.0, 255.0), dtype=np.uint8) save_image(x, "gen") x = np.ones((n_images, 3, w_in, w_in)).astype(np.uint8)*255 x[:,0,:,:] = 0 for i in range(12): x[:,0,:,:] += np.uint8(15*i*in_all[:,i,:,:]) save_image(x, "in", mode='HSV') x = np.asarray(np.clip(gt_all * 128+128, 0.0, 255.0), dtype=np.uint8) save_image(x, "gt") def main(): # ...snip trainer = training.Trainer( updater, (args.epoch, 'epoch'), out=args.out) trainer.extend( out_image( updater, enc, dec, 5, 5, args.seed, args.out), trigger=snapshot_interval) train_facade.py facade_visualizer.py
  16. 16. Example: pix2pix def out_image(updater, enc, dec, rows, cols, seed, dst): @chainer.training.make_extension() def make_image(trainer): # ...snip def save_image(x, name, mode=None): # ...snip x = np.asarray(np.clip(gen_all * 128 + 128, 0.0, 255.0), dtype=np.uint8) save_image(x, "gen") x = np.ones((n_images, 3, w_in, w_in)).astype(np.uint8)*255 x[:,0,:,:] = 0 for i in range(12): x[:,0,:,:] += np.uint8(15*i*in_all[:,i,:,:]) save_image(x, "in", mode='HSV') x = np.asarray(np.clip(gt_all * 128+128, 0.0, 255.0), dtype=np.uint8) save_image(x, "gt") def main(): # ...snip trainer = training.Trainer( updater, (args.epoch, 'epoch'), out=args.out) trainer.extend( out_image( updater, enc, dec, 5, 5, args.seed, args.out), trigger=snapshot_interval) visualizer = out_image(updater, enc, dec, args.visualize_batchsize, args.rows, args.seed) trainer.extend(chainerui.extensions.ImageReport( trigger=snapshot_interval, image_generator=visualizer)) summary.image(gen_all, name='gen', row=rows) summary.image(x, name='in', row=rows, mode='HSV') summary.image(gt_all, name='gt', row=rows)
  17. 17. Example: pix2pix web view
  18. 18. Demo https://github.com/disktnk/chainerui-demo-20180609
  19. 19. ImageReport TODO - Issue#101 - DB cache / lazy load / document etc... - API usability - Show images with label - Support grayscale - Support hidden layer?
  20. 20. Roadmap - v0.3.1 / v0.4 - output chart (PR#112) - print(‘msg’) → logger - improve UX - easy to distinguish each log chart - deal with too many columns or keys

×