Snapdragon Neural Processing Engine SDK
Reference Guide
PyTorch Model Conversion

Machine Learning frameworks have specific formats for storing neural network models. SNPE supports these various models by converting them to a framework neutral deep learning container (DLC) format. The DLC file is used by the SNPE runtime for execution of the neural network.

The snpe-pytorch-to-dlc tool converts a PyTorch TorchScript model into an equivalent SNPE DLC file. The following command will convert an ResNet18 PyTorch model into a SNPE DLC file.

snpe-pytorch-to-dlc --input_network resnet18.pt
                    --input_dim input "1,3,224,224"
                    --output_path resnet18.dlc

A trained PyTorch model can be converted to TorchScript model (.pt) file, the tutorial at https://pytorch.org/tutorials/advanced/cpp_export.html#converting-to-torch-script-via-tracing

Following code can be used to convert a pretrained PyTorch ResNet18 model to TorchScript (.pt) model.

import torch
import torchvision.models as models
resnet18_model = models.resnet18()
input_shape = [1, 3, 224, 224]
input_data = torch.randn(input_shape)
script_model = torch.jit.trace(resnet18_model, input_data)
script_model.save("resnet18.pt")

Note:

  • To check the list of currently supported PyTorch Ops, see Op Support Table
  • SNPE and PyTorch Converter currently only support float input data types