.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "build/examples_auto_module/demo_auto_detection.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_build_examples_auto_module_demo_auto_detection.py: 03. Train classifier or detector with HPO using GluonCV Auto task ==================================================================== The previous image classification example shows the basic usages to train/evaluate/predict using estimators provided by `gluoncv.auto.estimators`. Similarly, you can train object detectors using `SSDEstimator`, `YOLOv3Estimator`, `CenterNetEstimator`, `FasterRCNNEstimator`. In this tutorial, we will move forward a little bit, into the hyper-parameter tunning space! We will show you how to offload an experiment to the backend HPO searcher, to offer better result if computational cost is abundant. .. GENERATED FROM PYTHON SOURCE LINES 14-16 HPO with GluonCV auto tasks --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 16-20 .. code-block:: default from gluoncv.auto.tasks.image_classification import ImageClassification from gluoncv.auto.tasks.object_detection import ObjectDetection import autogluon.core as ag .. GENERATED FROM PYTHON SOURCE LINES 21-23 In this tutorial, we use a small sample dataset for object detection For image classification, please refer to :ref:`sphx_glr_build_examples_auto_module_train_image_classifier_basic.py`. .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: default train = ObjectDetection.Dataset.from_voc( 'https://autogluon.s3.amazonaws.com/datasets/tiny_motorbike.zip') train, val, test = train.random_split(val_size=0.1, test_size=0.1) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none tiny_motorbike/ ├── Annotations/ ├── ImageSets/ └── JPEGImages/ .. GENERATED FROM PYTHON SOURCE LINES 28-39 Define search space ------------------- We show a minimal example to run HPO for object detection. For image classification, the code change is negalected, just swap the dataset and `ObjectDetection` to `ImageClassification`. We use very conservative search space to reduce CI runtime, and we will cap the number of trials to be 1 to reduce building time, feel free to adjust the `num_trials`, `time_limits`, `epochs` and tune other search spaces with `ag.Categorical`, `ag.Int`, `ag.Real` for example in order to achieve better results .. GENERATED FROM PYTHON SOURCE LINES 39-49 .. code-block:: default time_limits = 60 * 60 # 1hr search_args = {'lr': ag.Categorical(1e-3, 1e-2), 'num_trials': 1, 'epochs': 2, 'num_workers': 16, 'batch_size': ag.Categorical(4, 8), 'ngpus_per_trial': 1, 'search_strategy': 'random', 'time_limits': time_limits} .. GENERATED FROM PYTHON SOURCE LINES 50-51 Construct a object detection task based on the config. .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: default task = ObjectDetection(search_args) .. GENERATED FROM PYTHON SOURCE LINES 54-55 Automatically fit a model. .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: default detector = task.fit(train, val) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /usr/local/lib/python3.6/dist-packages/mxnet/gluon/block.py:1512: 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 /root/.mxnet/models/ssd_512_resnet50_v1_coco-c4835162.zip from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/models/ssd_512_resnet50_v1_coco-c4835162.zip... 0%| | 0/181188 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_auto_detection.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_