Use with PyTorch model

In this tutorial, we’ll convert AlexNet [1] pretrained in PyTorch [2] into WebDNN execution format.

  1. Load PyTorch pretrained model
import torch, torchvision
from webdnn.frontend.pytorch import PyTorchConverter

model = torchvision.models.alexnet(pretrained=True)

graph = PyTorchConverter().convert(model, dummy_input)
  1. Prepare dummy input to construct computation graph
dummy_input = torch.autograd.Variable(torch.randn(1, 3, 224, 224))
  1. Convert to WebDNN graph
graph = PyTorchConverter().convert(model, dummy_input)
  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]Krizhevsky, Alex, Ilya Sutskever, and Geoffrey E. Hinton. “ImageNet Classification with Deep Convolutional Neural Networks.” Advances in neural information processing systems. 2012.
[2]https://pytorch.org