Use with Chainer model¶
In this tutorial, we’ll convert ResNet50 [1] classification model pretrained in Chainer [2] into WebDNN execution format.
- Load chainer pretrained model
import chainer
model = chainer.links.model.vision.resnet.ResNet50Layers()
- 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"]
- Convert chainer computation graph to our computation graph format
from webdnn.frontend.chainer import ChainerConverter
graph = ChainerConverter().convert([x], [y])
- 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] |
|
[2] | http://docs.chainer.org/en/latest/reference/links.html#chainer.links.ResNet50Layers |