Jun. 9th, 2018 @Preferred Networks
ChainerUI
v0.3 and ImageReport
ChainerUI
- mission
- Provide useful user interface for Chainer users!
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/
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!
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
Quick upgrade (to v0.3)
$ # stop chainerui server
$ pip install -U chainerui
$ chainerui db upgrade
$ chainerui server
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!
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
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
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))
Web view
Example: DCGAN
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
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()
Example: VAE (MNIST)
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
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)
Example: pix2pix
web view
Demo
https://github.com/disktnk/chainerui-demo-20180609
ImageReport TODO
- Issue#101
- DB cache / lazy load / document etc...
- API usability
- Show images with label
- Support grayscale
- Support hidden layer?
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
Chainer ui v0.3 and imagereport

More Related Content

PDF
Introduction to Chainer 11 may,2018
PDF
Chainer v4 and v5
PPTX
Chainer v3
PDF
Introduction to Chainer
PDF
Overview of Chainer and Its Features
PDF
CuPy v4 and v5 roadmap
PDF
Distributed Multi-GPU Computing with Dask, CuPy and RAPIDS
PDF
Chainer v2 alpha
Introduction to Chainer 11 may,2018
Chainer v4 and v5
Chainer v3
Introduction to Chainer
Overview of Chainer and Its Features
CuPy v4 and v5 roadmap
Distributed Multi-GPU Computing with Dask, CuPy and RAPIDS
Chainer v2 alpha

What's hot (20)

PDF
CuPy: A NumPy-compatible Library for GPU
PDF
Chainer Update v1.8.0 -> v1.10.0+
PDF
GTC Japan 2016 Chainer feature introduction
PDF
Comparison of deep learning frameworks from a viewpoint of double backpropaga...
PPTX
Deep parking
PDF
Accelerating microbiome research with OpenACC
PDF
CUDA and Caffe for deep learning
PDF
Slide tesi
PDF
PyTorch crash course
PDF
Advanced Spark and TensorFlow Meetup May 26, 2016
PPTX
PyTorch Tutorial for NTU Machine Learing Course 2017
PDF
Porting and optimizing UniFrac for GPUs
PDF
IIBMP2019 講演資料「オープンソースで始める深層学習」
PDF
Introduction to Chainer: A Flexible Framework for Deep Learning
PDF
Automatically Fusing Functions on CuPy
PDF
Introduction to Chainer
PDF
FCN-Based 6D Robotic Grasping for Arbitrary Placed Objects
PDF
Anirudh Koul. 30 Golden Rules of Deep Learning Performance
PDF
Introduction to Chainer
PDF
Tokyo Webmining Talk1
CuPy: A NumPy-compatible Library for GPU
Chainer Update v1.8.0 -> v1.10.0+
GTC Japan 2016 Chainer feature introduction
Comparison of deep learning frameworks from a viewpoint of double backpropaga...
Deep parking
Accelerating microbiome research with OpenACC
CUDA and Caffe for deep learning
Slide tesi
PyTorch crash course
Advanced Spark and TensorFlow Meetup May 26, 2016
PyTorch Tutorial for NTU Machine Learing Course 2017
Porting and optimizing UniFrac for GPUs
IIBMP2019 講演資料「オープンソースで始める深層学習」
Introduction to Chainer: A Flexible Framework for Deep Learning
Automatically Fusing Functions on CuPy
Introduction to Chainer
FCN-Based 6D Robotic Grasping for Arbitrary Placed Objects
Anirudh Koul. 30 Golden Rules of Deep Learning Performance
Introduction to Chainer
Tokyo Webmining Talk1
Ad

Similar to Chainer ui v0.3 and imagereport (20)

PDF
Icpp power ai-workshop 2018
PDF
OpenPOWER Workshop in Silicon Valley
PDF
Power ai tensorflowworkloadtutorial-20171117
PDF
DeepLearning ハンズオン資料 20161220
PDF
AIML4 CNN lab256 1hr (111-1).pdf
PPTX
Tutorial: Image Generation and Image-to-Image Translation using GAN
PDF
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
PPTX
Teach a neural network to read handwriting
PDF
GANS Project for Image idetification.pdf
PPTX
CNN_INTRO.pptx
PDF
Neural Networks in the Wild: Handwriting Recognition
PPTX
Image classification using cnn
PDF
Introduction to deep learning using python
PDF
Computer vision
PDF
Using the code below- I need help with creating code for the following.pdf
PPTX
Neural Networks with Google TensorFlow
DOCX
Digit recognition using mnist database
PDF
Deep Learning with Julia1.0 and Flux
PDF
A Tour of Tensorflow's APIs
PDF
Using the code below- I need help with the following 3 things- 1) Writ.pdf
Icpp power ai-workshop 2018
OpenPOWER Workshop in Silicon Valley
Power ai tensorflowworkloadtutorial-20171117
DeepLearning ハンズオン資料 20161220
AIML4 CNN lab256 1hr (111-1).pdf
Tutorial: Image Generation and Image-to-Image Translation using GAN
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Teach a neural network to read handwriting
GANS Project for Image idetification.pdf
CNN_INTRO.pptx
Neural Networks in the Wild: Handwriting Recognition
Image classification using cnn
Introduction to deep learning using python
Computer vision
Using the code below- I need help with creating code for the following.pdf
Neural Networks with Google TensorFlow
Digit recognition using mnist database
Deep Learning with Julia1.0 and Flux
A Tour of Tensorflow's APIs
Using the code below- I need help with the following 3 things- 1) Writ.pdf
Ad

More from Preferred Networks (20)

PDF
PodSecurityPolicy からGatekeeper に移行しました / Kubernetes Meetup Tokyo #57
PDF
Optunaを使ったHuman-in-the-loop最適化の紹介 - 2023/04/27 W&B 東京ミートアップ #3
PDF
Kubernetes + containerd で cgroup v2 に移行したら "failed to create fsnotify watcher...
PDF
深層学習の新しい応用と、 それを支える計算機の進化 - Preferred Networks CEO 西川徹 (SEMICON Japan 2022 Ke...
PDF
Kubernetes ControllerをScale-Outさせる方法 / Kubernetes Meetup Tokyo #55
PDF
Kaggle Happywhaleコンペ優勝解法でのOptuna使用事例 - 2022/12/10 Optuna Meetup #2
PDF
最新リリース:Optuna V3の全て - 2022/12/10 Optuna Meetup #2
PDF
Optuna Dashboardの紹介と設計解説 - 2022/12/10 Optuna Meetup #2
PDF
スタートアップが提案する2030年の材料開発 - 2022/11/11 QPARC講演
PPTX
Deep Learningのための専用プロセッサ「MN-Core」の開発と活用(2022/10/19東大大学院「 融合情報学特別講義Ⅲ」)
PPTX
PFNにおける研究開発(2022/10/19 東大大学院「融合情報学特別講義Ⅲ」)
PDF
自然言語処理を 役立てるのはなぜ難しいのか(2022/10/25東大大学院「自然言語処理応用」)
PDF
Kubernetes にこれから入るかもしれない注目機能!(2022年11月版) / TechFeed Experts Night #7 〜 コンテナ技術を語る
PDF
Matlantis™のニューラルネットワークポテンシャルPFPの適用範囲拡張
PDF
PFNのオンプレ計算機クラスタの取り組み_第55回情報科学若手の会
PDF
続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2
PDF
Kubernetes Service Account As Multi-Cloud Identity / Cloud Native Security Co...
PDF
KubeCon + CloudNativeCon Europe 2022 Recap / Kubernetes Meetup Tokyo #51 / #k...
PDF
KubeCon + CloudNativeCon Europe 2022 Recap - Batch/HPCの潮流とScheduler拡張事例 / Kub...
PDF
独断と偏見で選んだ Kubernetes 1.24 の注目機能と今後! / Kubernetes Meetup Tokyo 50
PodSecurityPolicy からGatekeeper に移行しました / Kubernetes Meetup Tokyo #57
Optunaを使ったHuman-in-the-loop最適化の紹介 - 2023/04/27 W&B 東京ミートアップ #3
Kubernetes + containerd で cgroup v2 に移行したら "failed to create fsnotify watcher...
深層学習の新しい応用と、 それを支える計算機の進化 - Preferred Networks CEO 西川徹 (SEMICON Japan 2022 Ke...
Kubernetes ControllerをScale-Outさせる方法 / Kubernetes Meetup Tokyo #55
Kaggle Happywhaleコンペ優勝解法でのOptuna使用事例 - 2022/12/10 Optuna Meetup #2
最新リリース:Optuna V3の全て - 2022/12/10 Optuna Meetup #2
Optuna Dashboardの紹介と設計解説 - 2022/12/10 Optuna Meetup #2
スタートアップが提案する2030年の材料開発 - 2022/11/11 QPARC講演
Deep Learningのための専用プロセッサ「MN-Core」の開発と活用(2022/10/19東大大学院「 融合情報学特別講義Ⅲ」)
PFNにおける研究開発(2022/10/19 東大大学院「融合情報学特別講義Ⅲ」)
自然言語処理を 役立てるのはなぜ難しいのか(2022/10/25東大大学院「自然言語処理応用」)
Kubernetes にこれから入るかもしれない注目機能!(2022年11月版) / TechFeed Experts Night #7 〜 コンテナ技術を語る
Matlantis™のニューラルネットワークポテンシャルPFPの適用範囲拡張
PFNのオンプレ計算機クラスタの取り組み_第55回情報科学若手の会
続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2
Kubernetes Service Account As Multi-Cloud Identity / Cloud Native Security Co...
KubeCon + CloudNativeCon Europe 2022 Recap / Kubernetes Meetup Tokyo #51 / #k...
KubeCon + CloudNativeCon Europe 2022 Recap - Batch/HPCの潮流とScheduler拡張事例 / Kub...
独断と偏見で選んだ Kubernetes 1.24 の注目機能と今後! / Kubernetes Meetup Tokyo 50

Recently uploaded (20)

PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PDF
Identification of potential depression in social media posts
PDF
Launch a Bumble-Style App with AI Features in 2025.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PDF
CEH Module 2 Footprinting CEH V13, concepts
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
PDF
NewMind AI Journal Monthly Chronicles - August 2025
PDF
Lung cancer patients survival prediction using outlier detection and optimize...
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PPTX
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
PPTX
How to Convert Tickets Into Sales Opportunity in Odoo 18
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
Examining Bias in AI Generated News Content.pdf
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PPTX
Presentation - Principles of Instructional Design.pptx
PDF
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
Rapid Prototyping: A lecture on prototyping techniques for interface design
Identification of potential depression in social media posts
Launch a Bumble-Style App with AI Features in 2025.pdf
NewMind AI Weekly Chronicles – August ’25 Week IV
Data Virtualization in Action: Scaling APIs and Apps with FME
CEH Module 2 Footprinting CEH V13, concepts
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
NewMind AI Journal Monthly Chronicles - August 2025
Lung cancer patients survival prediction using outlier detection and optimize...
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
How to Convert Tickets Into Sales Opportunity in Odoo 18
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
Examining Bias in AI Generated News Content.pdf
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Presentation - Principles of Instructional Design.pptx
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf

Chainer ui v0.3 and imagereport

  • 1. Jun. 9th, 2018 @Preferred Networks ChainerUI v0.3 and ImageReport
  • 2. ChainerUI - mission - Provide useful user interface for Chainer users!
  • 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. 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. 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. Quick upgrade (to v0.3) $ # stop chainerui server $ pip install -U chainerui $ chainerui db upgrade $ chainerui server
  • 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. 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. 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. 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))
  • 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. 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()
  • 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. 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)
  • 19. ImageReport TODO - Issue#101 - DB cache / lazy load / document etc... - API usability - Show images with label - Support grayscale - Support hidden layer?
  • 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