.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "how_to/deploy_models/deploy_ssd_gluoncv.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_how_to_deploy_models_deploy_ssd_gluoncv.py: Deploy Single Shot Multibox Detector(SSD) model =============================================== **Author**: `Yao Wang `_ `Leyuan Wang `_ This article is an introductory tutorial to deploy SSD models with TVM. We will use GluonCV pre-trained SSD model and convert it to Relay IR .. GENERATED FROM PYTHON SOURCE LINES 26-37 .. code-block:: default import tvm from tvm import te from matplotlib import pyplot as plt from tvm import relay from tvm.contrib import graph_executor from tvm.contrib.download import download_testdata from gluoncv import model_zoo, data, utils .. rst-class:: sphx-glr-script-out .. code-block:: none /usr/local/lib/python3.7/dist-packages/gluoncv/__init__.py:40: UserWarning: Both `mxnet==1.6.0` and `torch==1.11.0+cpu` are installed. You might encounter increased GPU memory footprint if both framework are used at the same time. warnings.warn(f'Both `mxnet=={mx.__version__}` and `torch=={torch.__version__}` are installed. ' .. GENERATED FROM PYTHON SOURCE LINES 43-65 Preliminary and Set parameters ------------------------------ .. note:: We support compiling SSD on both CPUs and GPUs now. To get best inference performance on CPU, change target argument according to your device and follow the :ref:`tune_relay_x86` to tune x86 CPU and :ref:`tune_relay_arm` for arm CPU. To get best inference performance on Intel graphics, change target argument to :code:`opencl -device=intel_graphics`. But when using Intel graphics on Mac, target needs to be set to `opencl` only for the reason that Intel subgroup extension is not supported on Mac. To get best inference performance on CUDA-based GPUs, change the target argument to :code:`cuda`; and for OPENCL-based GPUs, change target argument to :code:`opencl` followed by device argument according to your device. .. GENERATED FROM PYTHON SOURCE LINES 65-78 .. code-block:: default supported_model = [ "ssd_512_resnet50_v1_voc", "ssd_512_resnet50_v1_coco", "ssd_512_resnet101_v2_voc", "ssd_512_mobilenet1.0_voc", "ssd_512_mobilenet1.0_coco", "ssd_300_vgg16_atrous_voc" "ssd_512_vgg16_atrous_coco", ] model_name = supported_model[0] dshape = (1, 3, 512, 512) .. GENERATED FROM PYTHON SOURCE LINES 79-80 Download and pre-process demo image .. GENERATED FROM PYTHON SOURCE LINES 80-88 .. code-block:: default im_fname = download_testdata( "https://github.com/dmlc/web-data/blob/main/" + "gluoncv/detection/street_small.jpg?raw=true", "street_small.jpg", module="data", ) x, img = data.transforms.presets.ssd.load_test(im_fname, short=512) .. GENERATED FROM PYTHON SOURCE LINES 89-90 Convert and compile model for CPU. .. GENERATED FROM PYTHON SOURCE LINES 90-101 .. code-block:: default block = model_zoo.get_model(model_name, pretrained=True) def build(target): mod, params = relay.frontend.from_mxnet(block, {"data": dshape}) with tvm.transform.PassContext(opt_level=3): lib = relay.build(mod, target, params=params) return lib .. rst-class:: sphx-glr-script-out .. code-block:: none /usr/local/lib/python3.7/dist-packages/mxnet/gluon/block.py:1389: UserWarning: Cannot decide type for the following arguments. Consider providing them as input: data: None input_sym_arg_type = in_param.infer_type()[0] Downloading /workspace/.mxnet/models/ssd_512_resnet50_v1_voc-9c8b225a.zip from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/models/ssd_512_resnet50_v1_voc-9c8b225a.zip... 0%| | 0/132723 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: deploy_ssd_gluoncv.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_