Object Detection - Quick Start

Object detection is the process of identifying and localizing objects in an image and is an important task in computer vision. Follow this tutorial to learn how to use AutoGluon for object detection.

Tip: If you are new to AutoGluon, review Image Classification - Quick Start first to learn the basics of the AutoGluon API.

Our goal is to detect motorbike in images by YOLOv3 model. A tiny dataset is collected from VOC dataset, which only contains the motorbike category. The model pretrained on the COCO dataset is used to fine-tune our small dataset. With the help of AutoGluon, we are able to try many models with different hyperparameters automatically, and return the best one as our final model.

To start, import autogluon and ObjectDetection module as your task:

import autogluon as ag
from autogluon import ObjectDetection as task

Tiny_motorbike Dataset

We collect a toy dataset for detecting motorbikes in images. From the VOC dataset, images are randomly selected for training, validation, and testing - 120 images for training, 50 images for validation, and 50 for testing. This tiny dataset follows the same format as VOC.

Using the commands below, we can download this dataset, which is only 23M. The variable root specifies the path to store the dataset in. The name of unzipped folder is called tiny_motorbike.

root = './'
filename_zip = ag.download('https://autogluon.s3.amazonaws.com/datasets/tiny_motorbike.zip',
                        path=root)
filename = ag.unzip(filename_zip, root=root)
/var/lib/jenkins/miniconda3/envs/autogluon_docs-v0_0_15/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: should_run_async will not call transform_cell automatically in the future. Please pass the result to transformed_cell argument and any exception that happen during thetransform in preprocessing_exc_tuple in IPython 7.17 and above.
  and should_run_async(code)
Downloading ./tiny_motorbike.zip from https://autogluon.s3.amazonaws.com/datasets/tiny_motorbike.zip...
21273KB [00:00, 34709.26KB/s]

When we retrieve the dataset, we can create a dataset instance with its path and classes if it is a custom dataset.

import os
data_root = os.path.join(root, filename)
dataset_train = task.Dataset(data_root, classes=('motorbike',))
>>> create dataset(VOC format)

Fit Models by AutoGluon

In this section, we demonstrate how to apply AutoGluon to fit our detection models. We use mobilenet as the backbone for the YOLOv3 model. Two different learning rates are used to fine-tune the network. The best model is the one that obtains the best performance on the validation dataset. You can also try using more networks and hyperparameters to create a larger searching space.

We fit a classifier using AutoGluon as follows. In each experiment (one trial in our searching space), we train the model for 30 epochs.

time_limits = 5*60*60  # 5 hours
epochs = 30
detector = task.fit(dataset_train,
                    num_trials=2,
                    epochs=epochs,
                    lr=ag.Categorical(5e-4, 1e-4),
                    ngpus_per_trial=1,
                    time_limits=time_limits)
scheduler_options: Key 'training_history_callback_delta_secs': Imputing default value 60
scheduler_options: Key 'delay_get_config': Imputing default value True

Starting Experiments
Num of Finished Tasks is 0
Num of Pending Tasks is 2
scheduler: FIFOScheduler(
DistributedResourceManager{
(Remote: Remote REMOTE_ID: 0,
    <Remote: 'inproc://172.31.38.222/13480/1' processes=1 threads=8, memory=33.24 GB>, Resource: NodeResourceManager(8 CPUs, 1 GPUs))
})
HBox(children=(HTML(value=''), FloatProgress(value=0.0, max=2.0), HTML(value='')))
Time out (secs) is 18000
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f83cd339b90>, 'net': 'mobilenet1.0', 'lr': 0.0005, 'loss': SoftmaxCrossEntropyLoss(batch_axis=0, w=None), 'num_gpus': 1, 'batch_size': 16, 'split_ratio': 0.8, 'epochs': 30, 'num_workers': 8, 'hybridize': True, 'verbose': False, 'final_fit': False, 'seed': 223, 'data_shape': 416, 'start_epoch': 0, 'transfer': 'coco', 'lr_mode': 'step', 'lr_decay': 0.1, 'lr_decay_period': 0, 'lr_decay_epoch': '160,180', 'warmup_lr': 0.0, 'warmup_epochs': 2, 'warmup_iters': 1000, 'warmup_factor': 0.3333333333333333, 'momentum': 0.9, 'wd': 0.0005, 'log_interval': 100, 'save_prefix': 'yolo3_mobilenet1.0_custom', 'save_interval': 10, 'val_interval': 1, 'num_samples': -1, 'no_random_shape': False, 'no_wd': False, 'mixup': False, 'no_mixup_epochs': 20, 'label_smooth': False, 'resume': '', 'syncbn': False, 'reuse_pred_weights': True, 'task_id': 0}
[Epoch 0] Training cost: 6.073, ObjLoss=744.359,BoxCenterLoss=3.983,BoxScaleLoss=2.497,ClassLoss=1.000
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 5.697, ObjLoss=16.585,BoxCenterLoss=3.778,BoxScaleLoss=1.722,ClassLoss=0.775
[Epoch 1] Validation: motorbike=0.5157342657342657 mAP=0.5157342657342657
[Epoch 2] Training cost: 4.822, ObjLoss=20.386,BoxCenterLoss=3.706,BoxScaleLoss=1.195,ClassLoss=0.642
[Epoch 2] Validation: motorbike=0.3117383387028995 mAP=0.3117383387028995
[Epoch 3] Training cost: 4.580, ObjLoss=15.128,BoxCenterLoss=3.616,BoxScaleLoss=1.114,ClassLoss=0.579
[Epoch 3] Validation: motorbike=0.3911912222576545 mAP=0.3911912222576545
[Epoch 4] Training cost: 6.667, ObjLoss=13.507,BoxCenterLoss=3.872,BoxScaleLoss=1.118,ClassLoss=0.467
[Epoch 4] Validation: motorbike=0.4069177559650531 mAP=0.4069177559650531
[Epoch 5] Training cost: 3.580, ObjLoss=10.934,BoxCenterLoss=3.561,BoxScaleLoss=1.101,ClassLoss=0.481
[Epoch 5] Validation: motorbike=0.6533847364367349 mAP=0.6533847364367349
[Epoch 6] Training cost: 4.144, ObjLoss=7.094,BoxCenterLoss=3.409,BoxScaleLoss=0.932,ClassLoss=0.425
[Epoch 6] Validation: motorbike=0.819589815404963 mAP=0.819589815404963
[Epoch 7] Training cost: 6.783, ObjLoss=7.073,BoxCenterLoss=3.646,BoxScaleLoss=1.066,ClassLoss=0.327
[Epoch 7] Validation: motorbike=0.6642521994134898 mAP=0.6642521994134898
[Epoch 8] Training cost: 3.961, ObjLoss=5.436,BoxCenterLoss=3.437,BoxScaleLoss=0.965,ClassLoss=0.321
[Epoch 8] Validation: motorbike=0.6433892649301138 mAP=0.6433892649301138
[Epoch 9] Training cost: 4.227, ObjLoss=6.103,BoxCenterLoss=3.645,BoxScaleLoss=0.946,ClassLoss=0.381
[Epoch 9] Validation: motorbike=0.5842215031303596 mAP=0.5842215031303596
[Epoch 10] Training cost: 3.077, ObjLoss=7.073,BoxCenterLoss=3.479,BoxScaleLoss=0.958,ClassLoss=0.358
[Epoch 10] Validation: motorbike=0.7468559389776701 mAP=0.7468559389776701
[Epoch 11] Training cost: 5.427, ObjLoss=5.620,BoxCenterLoss=3.518,BoxScaleLoss=1.004,ClassLoss=0.235
[Epoch 11] Validation: motorbike=0.6747910735336365 mAP=0.6747910735336365
[Epoch 12] Training cost: 6.898, ObjLoss=6.503,BoxCenterLoss=3.696,BoxScaleLoss=0.902,ClassLoss=0.247
[Epoch 12] Validation: motorbike=0.8027261514310541 mAP=0.8027261514310541
[Epoch 13] Training cost: 4.962, ObjLoss=6.374,BoxCenterLoss=3.628,BoxScaleLoss=0.946,ClassLoss=0.273
[Epoch 13] Validation: motorbike=0.7196957367208471 mAP=0.7196957367208471
[Epoch 14] Training cost: 4.439, ObjLoss=4.691,BoxCenterLoss=3.584,BoxScaleLoss=0.953,ClassLoss=0.264
[Epoch 14] Validation: motorbike=0.8166369578134286 mAP=0.8166369578134286
[Epoch 15] Training cost: 8.114, ObjLoss=5.768,BoxCenterLoss=3.497,BoxScaleLoss=0.922,ClassLoss=0.190
[Epoch 15] Validation: motorbike=0.7907326291468858 mAP=0.7907326291468858
[Epoch 16] Training cost: 4.207, ObjLoss=4.840,BoxCenterLoss=3.380,BoxScaleLoss=0.909,ClassLoss=0.248
[Epoch 16] Validation: motorbike=0.515314889788574 mAP=0.515314889788574
[Epoch 17] Training cost: 5.773, ObjLoss=5.689,BoxCenterLoss=3.718,BoxScaleLoss=1.014,ClassLoss=0.219
[Epoch 17] Validation: motorbike=0.7436031218384157 mAP=0.7436031218384157
[Epoch 18] Training cost: 3.999, ObjLoss=4.229,BoxCenterLoss=3.462,BoxScaleLoss=0.913,ClassLoss=0.187
[Epoch 18] Validation: motorbike=0.7296247464503044 mAP=0.7296247464503044
[Epoch 19] Training cost: 4.584, ObjLoss=5.053,BoxCenterLoss=3.654,BoxScaleLoss=0.930,ClassLoss=0.216
[Epoch 19] Validation: motorbike=0.8364048178039679 mAP=0.8364048178039679
[Epoch 20] Training cost: 6.635, ObjLoss=4.683,BoxCenterLoss=3.416,BoxScaleLoss=0.721,ClassLoss=0.132
[Epoch 20] Validation: motorbike=0.8261534190335174 mAP=0.8261534190335174
[Epoch 21] Training cost: 4.109, ObjLoss=5.237,BoxCenterLoss=3.606,BoxScaleLoss=0.898,ClassLoss=0.262
[Epoch 21] Validation: motorbike=0.707261451998294 mAP=0.707261451998294
[Epoch 22] Training cost: 4.608, ObjLoss=4.407,BoxCenterLoss=3.422,BoxScaleLoss=0.831,ClassLoss=0.190
[Epoch 22] Validation: motorbike=0.7885793418051484 mAP=0.7885793418051484
[Epoch 23] Training cost: 3.709, ObjLoss=4.681,BoxCenterLoss=3.551,BoxScaleLoss=0.848,ClassLoss=0.212
[Epoch 23] Validation: motorbike=0.8240835701193758 mAP=0.8240835701193758
[Epoch 24] Training cost: 5.518, ObjLoss=4.437,BoxCenterLoss=3.332,BoxScaleLoss=0.728,ClassLoss=0.125
[Epoch 24] Validation: motorbike=0.8597668997668998 mAP=0.8597668997668998
[Epoch 25] Training cost: 4.701, ObjLoss=4.078,BoxCenterLoss=3.458,BoxScaleLoss=0.820,ClassLoss=0.153
[Epoch 25] Validation: motorbike=0.8459810289230452 mAP=0.8459810289230452
[Epoch 26] Training cost: 4.392, ObjLoss=3.843,BoxCenterLoss=3.515,BoxScaleLoss=0.792,ClassLoss=0.137
[Epoch 26] Validation: motorbike=0.8702153110047848 mAP=0.8702153110047848
[Epoch 27] Training cost: 6.819, ObjLoss=4.162,BoxCenterLoss=3.257,BoxScaleLoss=0.756,ClassLoss=0.084
[Epoch 27] Validation: motorbike=0.736742343676142 mAP=0.736742343676142
[Epoch 28] Training cost: 3.565, ObjLoss=4.374,BoxCenterLoss=3.510,BoxScaleLoss=0.985,ClassLoss=0.163
[Epoch 28] Validation: motorbike=0.8266987762617861 mAP=0.8266987762617861
[Epoch 29] Training cost: 6.614, ObjLoss=4.648,BoxCenterLoss=3.344,BoxScaleLoss=0.866,ClassLoss=0.097
[Epoch 29] Validation: motorbike=0.7788725973703334 mAP=0.7788725973703334
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f82cbe2a610>, 'net': 'mobilenet1.0', 'lr': 0.0001, 'loss': SoftmaxCrossEntropyLoss(batch_axis=0, w=None), 'num_gpus': 1, 'batch_size': 16, 'split_ratio': 0.8, 'epochs': 30, 'num_workers': 8, 'hybridize': True, 'verbose': False, 'final_fit': False, 'seed': 223, 'data_shape': 416, 'start_epoch': 0, 'transfer': 'coco', 'lr_mode': 'step', 'lr_decay': 0.1, 'lr_decay_period': 0, 'lr_decay_epoch': '160,180', 'warmup_lr': 0.0, 'warmup_epochs': 2, 'warmup_iters': 1000, 'warmup_factor': 0.3333333333333333, 'momentum': 0.9, 'wd': 0.0005, 'log_interval': 100, 'save_prefix': 'yolo3_mobilenet1.0_custom', 'save_interval': 10, 'val_interval': 1, 'num_samples': -1, 'no_random_shape': False, 'no_wd': False, 'mixup': False, 'no_mixup_epochs': 20, 'label_smooth': False, 'resume': '', 'syncbn': False, 'reuse_pred_weights': True, 'task_id': 1}
[Epoch 0] Training cost: 5.969, ObjLoss=887.277,BoxCenterLoss=3.937,BoxScaleLoss=3.134,ClassLoss=1.063
[Epoch 0] Validation: motorbike=0.015466397092239799 mAP=0.015466397092239799
[Epoch 1] Training cost: 5.937, ObjLoss=16.562,BoxCenterLoss=3.739,BoxScaleLoss=2.240,ClassLoss=0.961
[Epoch 1] Validation: motorbike=0.0 mAP=0.0
[Epoch 2] Training cost: 5.029, ObjLoss=13.477,BoxCenterLoss=3.625,BoxScaleLoss=1.660,ClassLoss=0.764
[Epoch 2] Validation: motorbike=0.23529411764705882 mAP=0.23529411764705882
[Epoch 3] Training cost: 5.369, ObjLoss=12.895,BoxCenterLoss=3.757,BoxScaleLoss=1.567,ClassLoss=0.728
[Epoch 3] Validation: motorbike=0.24733690343112075 mAP=0.24733690343112075
[Epoch 4] Training cost: 7.062, ObjLoss=9.657,BoxCenterLoss=3.653,BoxScaleLoss=1.317,ClassLoss=0.648
[Epoch 4] Validation: motorbike=0.4518999518999519 mAP=0.4518999518999519
[Epoch 5] Training cost: 3.717, ObjLoss=8.331,BoxCenterLoss=3.604,BoxScaleLoss=1.366,ClassLoss=0.651
[Epoch 5] Validation: motorbike=0.5964895092369193 mAP=0.5964895092369193
[Epoch 6] Training cost: 3.999, ObjLoss=6.376,BoxCenterLoss=3.460,BoxScaleLoss=1.282,ClassLoss=0.607
[Epoch 6] Validation: motorbike=0.6016802861302387 mAP=0.6016802861302387
[Epoch 7] Training cost: 7.186, ObjLoss=7.217,BoxCenterLoss=3.751,BoxScaleLoss=1.175,ClassLoss=0.558
[Epoch 7] Validation: motorbike=0.6129028225941834 mAP=0.6129028225941834
[Epoch 8] Training cost: 3.900, ObjLoss=6.367,BoxCenterLoss=3.638,BoxScaleLoss=1.260,ClassLoss=0.548
[Epoch 8] Validation: motorbike=0.724486301369863 mAP=0.724486301369863
[Epoch 9] Training cost: 4.547, ObjLoss=5.901,BoxCenterLoss=3.650,BoxScaleLoss=1.146,ClassLoss=0.557
[Epoch 9] Validation: motorbike=0.6649665138015108 mAP=0.6649665138015108
[Epoch 10] Training cost: 3.197, ObjLoss=6.115,BoxCenterLoss=3.605,BoxScaleLoss=1.167,ClassLoss=0.582
[Epoch 10] Validation: motorbike=0.6770024519385133 mAP=0.6770024519385133
[Epoch 11] Training cost: 6.047, ObjLoss=6.068,BoxCenterLoss=3.685,BoxScaleLoss=1.153,ClassLoss=0.448
[Epoch 11] Validation: motorbike=0.7812090904074406 mAP=0.7812090904074406
[Epoch 12] Training cost: 7.520, ObjLoss=5.715,BoxCenterLoss=3.738,BoxScaleLoss=1.015,ClassLoss=0.421
[Epoch 12] Validation: motorbike=0.7852101986535595 mAP=0.7852101986535595
[Epoch 13] Training cost: 5.149, ObjLoss=5.285,BoxCenterLoss=3.502,BoxScaleLoss=1.029,ClassLoss=0.460
[Epoch 13] Validation: motorbike=0.7872033219945831 mAP=0.7872033219945831
[Epoch 14] Training cost: 4.347, ObjLoss=5.127,BoxCenterLoss=3.667,BoxScaleLoss=1.063,ClassLoss=0.437
[Epoch 14] Validation: motorbike=0.7849332485696122 mAP=0.7849332485696122
[Epoch 15] Training cost: 8.508, ObjLoss=5.539,BoxCenterLoss=3.594,BoxScaleLoss=0.957,ClassLoss=0.333
[Epoch 15] Validation: motorbike=0.7937860867695286 mAP=0.7937860867695286
[Epoch 16] Training cost: 3.702, ObjLoss=5.023,BoxCenterLoss=3.437,BoxScaleLoss=1.071,ClassLoss=0.415
[Epoch 16] Validation: motorbike=0.8077861521432289 mAP=0.8077861521432289
[Epoch 17] Training cost: 6.315, ObjLoss=4.922,BoxCenterLoss=3.590,BoxScaleLoss=0.958,ClassLoss=0.325
[Epoch 17] Validation: motorbike=0.8086210847975553 mAP=0.8086210847975553
[Epoch 18] Training cost: 4.577, ObjLoss=4.579,BoxCenterLoss=3.432,BoxScaleLoss=0.981,ClassLoss=0.349
[Epoch 18] Validation: motorbike=0.8079741520162083 mAP=0.8079741520162083
[Epoch 19] Training cost: 4.956, ObjLoss=4.951,BoxCenterLoss=3.612,BoxScaleLoss=0.913,ClassLoss=0.357
[Epoch 19] Validation: motorbike=0.8201298701298703 mAP=0.8201298701298703
[Epoch 20] Training cost: 6.667, ObjLoss=4.923,BoxCenterLoss=3.457,BoxScaleLoss=0.860,ClassLoss=0.262
[Epoch 20] Validation: motorbike=0.7928077952271501 mAP=0.7928077952271501
[Epoch 21] Training cost: 3.796, ObjLoss=4.713,BoxCenterLoss=3.517,BoxScaleLoss=0.945,ClassLoss=0.367
[Epoch 21] Validation: motorbike=0.8402561870414129 mAP=0.8402561870414129
[Epoch 22] Training cost: 4.340, ObjLoss=4.635,BoxCenterLoss=3.629,BoxScaleLoss=0.950,ClassLoss=0.342
[Epoch 22] Validation: motorbike=0.8410048501430172 mAP=0.8410048501430172
[Epoch 23] Training cost: 4.186, ObjLoss=4.716,BoxCenterLoss=3.626,BoxScaleLoss=0.946,ClassLoss=0.390
[Epoch 23] Validation: motorbike=0.8492965367965369 mAP=0.8492965367965369
[Epoch 24] Training cost: 5.730, ObjLoss=4.833,BoxCenterLoss=3.636,BoxScaleLoss=0.867,ClassLoss=0.259
[Epoch 24] Validation: motorbike=0.8400838633396774 mAP=0.8400838633396774
[Epoch 25] Training cost: 4.669, ObjLoss=4.302,BoxCenterLoss=3.450,BoxScaleLoss=0.900,ClassLoss=0.317
[Epoch 25] Validation: motorbike=0.8328875802560014 mAP=0.8328875802560014
[Epoch 26] Training cost: 4.183, ObjLoss=4.557,BoxCenterLoss=3.477,BoxScaleLoss=0.785,ClassLoss=0.294
[Epoch 26] Validation: motorbike=0.810298637373567 mAP=0.810298637373567
[Epoch 27] Training cost: 7.084, ObjLoss=4.927,BoxCenterLoss=3.581,BoxScaleLoss=0.850,ClassLoss=0.273
[Epoch 27] Validation: motorbike=0.8399718515777373 mAP=0.8399718515777373
[Epoch 28] Training cost: 3.190, ObjLoss=4.666,BoxCenterLoss=3.470,BoxScaleLoss=0.896,ClassLoss=0.332
[Epoch 28] Validation: motorbike=0.8228311543528936 mAP=0.8228311543528936
[Epoch 29] Training cost: 6.776, ObjLoss=4.645,BoxCenterLoss=3.372,BoxScaleLoss=0.814,ClassLoss=0.195
[Epoch 29] Validation: motorbike=0.8351941687406348 mAP=0.8351941687406348
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f82cbe939d0>, 'net': 'mobilenet1.0', 'lr': 0.0001, 'loss': SoftmaxCrossEntropyLoss(batch_axis=0, w=None), 'num_gpus': 1, 'batch_size': 16, 'split_ratio': 0.8, 'epochs': 30, 'num_workers': 8, 'hybridize': True, 'verbose': False, 'final_fit': True, 'seed': 223, 'data_shape': 416, 'start_epoch': 0, 'transfer': 'coco', 'lr_mode': 'step', 'lr_decay': 0.1, 'lr_decay_period': 0, 'lr_decay_epoch': '160,180', 'warmup_lr': 0.0, 'warmup_epochs': 2, 'warmup_iters': 1000, 'warmup_factor': 0.3333333333333333, 'momentum': 0.9, 'wd': 0.0005, 'log_interval': 100, 'save_prefix': 'yolo3_mobilenet1.0_custom', 'save_interval': 10, 'val_interval': 1, 'num_samples': -1, 'no_random_shape': False, 'no_wd': False, 'mixup': False, 'no_mixup_epochs': 20, 'label_smooth': False, 'resume': '', 'syncbn': False, 'reuse_pred_weights': True, 'task_id': 2}
[Epoch 0] Training cost: 6.721, ObjLoss=713.648,BoxCenterLoss=3.869,BoxScaleLoss=3.066,ClassLoss=1.064
[Epoch 1] Training cost: 5.549, ObjLoss=15.037,BoxCenterLoss=3.611,BoxScaleLoss=2.069,ClassLoss=0.878
[Epoch 2] Training cost: 6.634, ObjLoss=13.405,BoxCenterLoss=3.795,BoxScaleLoss=1.684,ClassLoss=0.735
[Epoch 3] Training cost: 9.596, ObjLoss=9.890,BoxCenterLoss=3.695,BoxScaleLoss=1.432,ClassLoss=0.672
[Epoch 4] Training cost: 5.517, ObjLoss=7.603,BoxCenterLoss=3.601,BoxScaleLoss=1.384,ClassLoss=0.654
[Epoch 5] Training cost: 7.928, ObjLoss=7.217,BoxCenterLoss=3.666,BoxScaleLoss=1.218,ClassLoss=0.547
[Epoch 6] Training cost: 8.240, ObjLoss=6.098,BoxCenterLoss=3.494,BoxScaleLoss=1.141,ClassLoss=0.449
[Epoch 7] Training cost: 5.205, ObjLoss=5.872,BoxCenterLoss=3.517,BoxScaleLoss=1.137,ClassLoss=0.526
[Epoch 8] Training cost: 7.985, ObjLoss=6.154,BoxCenterLoss=3.660,BoxScaleLoss=1.150,ClassLoss=0.477
[Epoch 9] Training cost: 6.798, ObjLoss=5.443,BoxCenterLoss=3.542,BoxScaleLoss=1.026,ClassLoss=0.423
[Epoch 10] Training cost: 5.147, ObjLoss=5.508,BoxCenterLoss=3.524,BoxScaleLoss=1.057,ClassLoss=0.440
[Epoch 11] Training cost: 6.622, ObjLoss=5.389,BoxCenterLoss=3.681,BoxScaleLoss=1.024,ClassLoss=0.425
[Epoch 12] Training cost: 6.961, ObjLoss=5.102,BoxCenterLoss=3.554,BoxScaleLoss=0.993,ClassLoss=0.388
[Epoch 13] Training cost: 8.804, ObjLoss=6.009,BoxCenterLoss=3.499,BoxScaleLoss=0.986,ClassLoss=0.278
[Epoch 14] Training cost: 7.018, ObjLoss=5.608,BoxCenterLoss=3.785,BoxScaleLoss=1.117,ClassLoss=0.375
[Epoch 15] Training cost: 5.803, ObjLoss=4.674,BoxCenterLoss=3.425,BoxScaleLoss=0.892,ClassLoss=0.289
[Epoch 16] Training cost: 3.982, ObjLoss=4.893,BoxCenterLoss=3.576,BoxScaleLoss=1.090,ClassLoss=0.387
[Epoch 17] Training cost: 4.587, ObjLoss=4.568,BoxCenterLoss=3.558,BoxScaleLoss=1.013,ClassLoss=0.368
[Epoch 18] Training cost: 8.698, ObjLoss=5.352,BoxCenterLoss=3.576,BoxScaleLoss=1.011,ClassLoss=0.278
[Epoch 19] Training cost: 4.237, ObjLoss=4.405,BoxCenterLoss=3.307,BoxScaleLoss=0.959,ClassLoss=0.330
[Epoch 20] Training cost: 5.826, ObjLoss=4.837,BoxCenterLoss=3.676,BoxScaleLoss=1.033,ClassLoss=0.325
[Epoch 21] Training cost: 6.306, ObjLoss=4.608,BoxCenterLoss=3.415,BoxScaleLoss=0.901,ClassLoss=0.259
[Epoch 22] Training cost: 6.104, ObjLoss=4.525,BoxCenterLoss=3.506,BoxScaleLoss=0.988,ClassLoss=0.280
[Epoch 23] Training cost: 5.522, ObjLoss=4.542,BoxCenterLoss=3.609,BoxScaleLoss=0.922,ClassLoss=0.287
[Epoch 24] Training cost: 6.899, ObjLoss=4.808,BoxCenterLoss=3.534,BoxScaleLoss=0.930,ClassLoss=0.245
[Epoch 25] Training cost: 8.997, ObjLoss=4.538,BoxCenterLoss=3.537,BoxScaleLoss=0.826,ClassLoss=0.203
[Epoch 26] Training cost: 6.436, ObjLoss=4.752,BoxCenterLoss=3.429,BoxScaleLoss=0.841,ClassLoss=0.223
[Epoch 27] Training cost: 6.208, ObjLoss=4.029,BoxCenterLoss=3.373,BoxScaleLoss=0.784,ClassLoss=0.205
[Epoch 28] Training cost: 8.885, ObjLoss=4.933,BoxCenterLoss=3.520,BoxScaleLoss=0.965,ClassLoss=0.207
[Epoch 29] Training cost: 4.649, ObjLoss=4.296,BoxCenterLoss=3.374,BoxScaleLoss=1.000,ClassLoss=0.255
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> finish model fitting
The best config: {'lr▁choice': 1, 'net▁choice': 0}

Note that num_trials=2 above is only used to speed up the tutorial. In normal practice, it is common to only use time_limits and drop num_trials.

After fitting, AutoGluon automatically returns the best model among all models in the searching space. From the output, we know the best model is the one trained with the second learning rate. To see how well the returned model performed on test dataset, call detector.evaluate().

dataset_test = task.Dataset(data_root, index_file_name='test', classes=('motorbike',))

test_map = detector.evaluate(dataset_test)
print("mAP on test dataset: {}".format(test_map[1][1]))
/var/lib/jenkins/miniconda3/envs/autogluon_docs-v0_0_15/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: should_run_async will not call transform_cell automatically in the future. Please pass the result to transformed_cell argument and any exception that happen during thetransform in preprocessing_exc_tuple in IPython 7.17 and above.
  and should_run_async(code)
>>> create dataset(VOC format)
mAP on test dataset: 0.8142798225247281

Below, we randomly select an image from test dataset and show the predicted box and probability over the origin image.

image = '000467.jpg'
image_path = os.path.join(data_root, 'JPEGImages', image)

ind, prob, loc = detector.predict(image_path)
../../_images/output_beginner_1fd7a6_11_0.png

We can also save the trained model, and use it later.

savefile = 'model.pkl'
detector.save(savefile)

from autogluon import Detector
new_detector = Detector.load(savefile)