Use with Chainer model

In this tutorial, we’ll convert ResNet50 [1] classification model pretrained in Chainer [2] into WebDNN execution format.

  1. Load chainer pretrained model
import chainer

model = chainer.links.model.vision.resnet.ResNet50Layers()
  1. Execute model with dummy data. In chainer, computation graph are defined by run. Therefore we need execute model at least once to construct the graph.
import numpy as np

x = chainer.Variable(np.empty((1, 3, 224, 224), dtype=np.float32))
y = model(x, layers=["fc6"])["fc6"]
  1. Convert chainer computation graph to our computation graph format
from webdnn.frontend.chainer import ChainerConverter

graph = ChainerConverter().convert([x], [y])
  1. Generate and save execution information.
from webdnn.backend import generate_descriptor

exec_info = generate_descriptor("webgpu", graph)  # also "webassembly", "webgl", "fallback" are available.
exec_info.save("./output")

To run converted model on web browser, please see “#3. Run on web browser” in keras tutorial

References

[1]
  1. He, X. Zhang, S. Ren, and J. Sun, “Deep Residual Learning for Image Recognition”, IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016.
[2]http://docs.chainer.org/en/latest/reference/links.html#chainer.links.ResNet50Layers