Deploying custom Detectron2 models
The previous section described the model formats and respective runtimes for PyTorch. It also used simple models for illustration purposes. This section will focus on deploying custom Detectron2 models into server environments using the techniques described in the previous section. This section will first describe the main export utilities that Detectron2 provides to support exporting its models. It will then provide the code to export a custom Detectron2 model into TorchScript using the tracing and scripting approaches.
Detectron2 utilities for exporting models
Detectron2 provides a wrapper class called TracingAdapter
, which helps wrap a Detectron2 model and supports exports using the tracing method. Detectron2 models take rich inputs and also produce rich outputs (i.e., they can be dictionaries or objects). Conversely, the tracing function (torch.jit.trace
) takes tensors as inputs/outputs. Therefore, this adapter class helps flatten the inputs...