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_14/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, 45949.88KB/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.39.52/26315/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 0x7f5e0e88df90>, '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: 7.094, ObjLoss=1354.590,BoxCenterLoss=3.764,BoxScaleLoss=2.344,ClassLoss=0.954
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 4.949, ObjLoss=34.579,BoxCenterLoss=3.735,BoxScaleLoss=1.706,ClassLoss=0.835
[Epoch 1] Validation: motorbike=0.010119724668207899 mAP=0.010119724668207899
[Epoch 2] Training cost: 4.834, ObjLoss=34.266,BoxCenterLoss=3.597,BoxScaleLoss=1.360,ClassLoss=0.733
[Epoch 2] Validation: motorbike=0.07599190594998408 mAP=0.07599190594998408
[Epoch 3] Training cost: 7.752, ObjLoss=12.585,BoxCenterLoss=3.612,BoxScaleLoss=1.097,ClassLoss=0.550
[Epoch 3] Validation: motorbike=0.0862087111777578 mAP=0.0862087111777578
[Epoch 4] Training cost: 3.903, ObjLoss=15.731,BoxCenterLoss=3.668,BoxScaleLoss=1.157,ClassLoss=0.583
[Epoch 4] Validation: motorbike=0.10261323246191308 mAP=0.10261323246191308
[Epoch 5] Training cost: 4.670, ObjLoss=14.181,BoxCenterLoss=3.606,BoxScaleLoss=0.976,ClassLoss=0.505
[Epoch 5] Validation: motorbike=0.19461354188154134 mAP=0.19461354188154134
[Epoch 6] Training cost: 3.967, ObjLoss=10.741,BoxCenterLoss=3.703,BoxScaleLoss=1.026,ClassLoss=0.497
[Epoch 6] Validation: motorbike=0.6145882075576802 mAP=0.6145882075576802
[Epoch 7] Training cost: 3.222, ObjLoss=11.789,BoxCenterLoss=3.601,BoxScaleLoss=0.974,ClassLoss=0.497
[Epoch 7] Validation: motorbike=0.6694335675634501 mAP=0.6694335675634501
[Epoch 8] Training cost: 3.478, ObjLoss=18.883,BoxCenterLoss=3.477,BoxScaleLoss=0.978,ClassLoss=0.426
[Epoch 8] Validation: motorbike=0.5572032039418829 mAP=0.5572032039418829
[Epoch 9] Training cost: 6.650, ObjLoss=14.651,BoxCenterLoss=3.832,BoxScaleLoss=1.002,ClassLoss=0.319
[Epoch 9] Validation: motorbike=0.7389033033316155 mAP=0.7389033033316155
[Epoch 10] Training cost: 3.691, ObjLoss=22.051,BoxCenterLoss=3.540,BoxScaleLoss=1.010,ClassLoss=0.349
[Epoch 10] Validation: motorbike=0.6786138662343104 mAP=0.6786138662343104
[Epoch 11] Training cost: 3.929, ObjLoss=19.849,BoxCenterLoss=3.658,BoxScaleLoss=1.010,ClassLoss=0.349
[Epoch 11] Validation: motorbike=0.7515731477453965 mAP=0.7515731477453965
[Epoch 12] Training cost: 5.091, ObjLoss=6.994,BoxCenterLoss=3.614,BoxScaleLoss=0.934,ClassLoss=0.259
[Epoch 12] Validation: motorbike=0.6590989637462202 mAP=0.6590989637462202
[Epoch 13] Training cost: 4.040, ObjLoss=13.756,BoxCenterLoss=3.706,BoxScaleLoss=1.006,ClassLoss=0.334
[Epoch 13] Validation: motorbike=0.7798589502319775 mAP=0.7798589502319775
[Epoch 14] Training cost: 3.905, ObjLoss=7.873,BoxCenterLoss=3.473,BoxScaleLoss=0.945,ClassLoss=0.234
[Epoch 14] Validation: motorbike=0.7517860773438867 mAP=0.7517860773438867
[Epoch 15] Training cost: 3.655, ObjLoss=15.918,BoxCenterLoss=3.658,BoxScaleLoss=0.967,ClassLoss=0.341
[Epoch 15] Validation: motorbike=0.7173220948390611 mAP=0.7173220948390611
[Epoch 16] Training cost: 4.562, ObjLoss=9.869,BoxCenterLoss=3.427,BoxScaleLoss=0.871,ClassLoss=0.209
[Epoch 16] Validation: motorbike=0.6648042713133958 mAP=0.6648042713133958
[Epoch 17] Training cost: 4.593, ObjLoss=17.820,BoxCenterLoss=3.791,BoxScaleLoss=1.048,ClassLoss=0.310
[Epoch 17] Validation: motorbike=0.7767144898804713 mAP=0.7767144898804713
[Epoch 18] Training cost: 4.270, ObjLoss=14.230,BoxCenterLoss=3.563,BoxScaleLoss=0.924,ClassLoss=0.248
[Epoch 18] Validation: motorbike=0.7656476406476407 mAP=0.7656476406476407
[Epoch 19] Training cost: 3.729, ObjLoss=16.829,BoxCenterLoss=3.482,BoxScaleLoss=0.997,ClassLoss=0.288
[Epoch 19] Validation: motorbike=0.770958021439408 mAP=0.770958021439408
[Epoch 20] Training cost: 4.492, ObjLoss=9.294,BoxCenterLoss=3.408,BoxScaleLoss=0.810,ClassLoss=0.189
[Epoch 20] Validation: motorbike=0.776630077868468 mAP=0.776630077868468
[Epoch 21] Training cost: 6.846, ObjLoss=8.035,BoxCenterLoss=3.370,BoxScaleLoss=0.856,ClassLoss=0.186
[Epoch 21] Validation: motorbike=0.7495736267338702 mAP=0.7495736267338702
[Epoch 22] Training cost: 4.693, ObjLoss=5.676,BoxCenterLoss=3.461,BoxScaleLoss=0.835,ClassLoss=0.186
[Epoch 22] Validation: motorbike=0.7557004508713465 mAP=0.7557004508713465
[Epoch 23] Training cost: 8.193, ObjLoss=6.050,BoxCenterLoss=3.623,BoxScaleLoss=0.856,ClassLoss=0.173
[Epoch 23] Validation: motorbike=0.7574199171461171 mAP=0.7574199171461171
[Epoch 24] Training cost: 5.536, ObjLoss=5.585,BoxCenterLoss=3.545,BoxScaleLoss=0.870,ClassLoss=0.190
[Epoch 24] Validation: motorbike=0.7735987581442129 mAP=0.7735987581442129
[Epoch 25] Training cost: 6.935, ObjLoss=5.692,BoxCenterLoss=3.536,BoxScaleLoss=0.912,ClassLoss=0.152
[Epoch 25] Validation: motorbike=0.7176287484238213 mAP=0.7176287484238213
[Epoch 26] Training cost: 6.274, ObjLoss=5.551,BoxCenterLoss=3.356,BoxScaleLoss=0.747,ClassLoss=0.129
[Epoch 26] Validation: motorbike=0.7390435038811299 mAP=0.7390435038811299
[Epoch 27] Training cost: 4.362, ObjLoss=6.386,BoxCenterLoss=3.380,BoxScaleLoss=0.789,ClassLoss=0.201
[Epoch 27] Validation: motorbike=0.7578774303512978 mAP=0.7578774303512978
[Epoch 28] Training cost: 4.920, ObjLoss=4.576,BoxCenterLoss=3.409,BoxScaleLoss=0.775,ClassLoss=0.189
[Epoch 28] Validation: motorbike=0.7604482929053201 mAP=0.7604482929053201
[Epoch 29] Training cost: 4.082, ObjLoss=4.872,BoxCenterLoss=3.305,BoxScaleLoss=0.815,ClassLoss=0.179
[Epoch 29] Validation: motorbike=0.8366098625871523 mAP=0.8366098625871523
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f5d45270110>, '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: 7.260, ObjLoss=1467.217,BoxCenterLoss=4.002,BoxScaleLoss=3.054,ClassLoss=1.085
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 4.923, ObjLoss=20.397,BoxCenterLoss=3.841,BoxScaleLoss=2.134,ClassLoss=0.852
[Epoch 1] Validation: motorbike=0.0 mAP=0.0
[Epoch 2] Training cost: 4.736, ObjLoss=19.356,BoxCenterLoss=3.638,BoxScaleLoss=1.697,ClassLoss=0.751
[Epoch 2] Validation: motorbike=0.09090909090909091 mAP=0.09090909090909091
[Epoch 3] Training cost: 7.858, ObjLoss=12.287,BoxCenterLoss=3.680,BoxScaleLoss=1.508,ClassLoss=0.736
[Epoch 3] Validation: motorbike=0.34540593096742833 mAP=0.34540593096742833
[Epoch 4] Training cost: 4.122, ObjLoss=10.138,BoxCenterLoss=3.738,BoxScaleLoss=1.537,ClassLoss=0.758
[Epoch 4] Validation: motorbike=0.42157943067033976 mAP=0.42157943067033976
[Epoch 5] Training cost: 4.426, ObjLoss=7.095,BoxCenterLoss=3.478,BoxScaleLoss=1.254,ClassLoss=0.648
[Epoch 5] Validation: motorbike=0.49649536956670176 mAP=0.49649536956670176
[Epoch 6] Training cost: 4.025, ObjLoss=6.899,BoxCenterLoss=3.505,BoxScaleLoss=1.247,ClassLoss=0.647
[Epoch 6] Validation: motorbike=0.5803817676738963 mAP=0.5803817676738963
[Epoch 7] Training cost: 3.716, ObjLoss=6.894,BoxCenterLoss=3.575,BoxScaleLoss=1.239,ClassLoss=0.682
[Epoch 7] Validation: motorbike=0.6033042597524627 mAP=0.6033042597524627
[Epoch 8] Training cost: 3.306, ObjLoss=6.572,BoxCenterLoss=3.567,BoxScaleLoss=1.157,ClassLoss=0.670
[Epoch 8] Validation: motorbike=0.6399572247326824 mAP=0.6399572247326824
[Epoch 9] Training cost: 7.221, ObjLoss=7.208,BoxCenterLoss=3.918,BoxScaleLoss=1.169,ClassLoss=0.597
[Epoch 9] Validation: motorbike=0.6893018991606736 mAP=0.6893018991606736
[Epoch 10] Training cost: 3.823, ObjLoss=5.579,BoxCenterLoss=3.531,BoxScaleLoss=1.155,ClassLoss=0.554
[Epoch 10] Validation: motorbike=0.6771377224733787 mAP=0.6771377224733787
[Epoch 11] Training cost: 3.949, ObjLoss=6.063,BoxCenterLoss=3.540,BoxScaleLoss=1.005,ClassLoss=0.549
[Epoch 11] Validation: motorbike=0.705845902499615 mAP=0.705845902499615
[Epoch 12] Training cost: 5.310, ObjLoss=5.605,BoxCenterLoss=3.684,BoxScaleLoss=0.918,ClassLoss=0.463
[Epoch 12] Validation: motorbike=0.7694985121729307 mAP=0.7694985121729307
[Epoch 13] Training cost: 3.681, ObjLoss=6.061,BoxCenterLoss=3.732,BoxScaleLoss=1.083,ClassLoss=0.550
[Epoch 13] Validation: motorbike=0.7779890068164188 mAP=0.7779890068164188
[Epoch 14] Training cost: 4.146, ObjLoss=5.183,BoxCenterLoss=3.515,BoxScaleLoss=0.944,ClassLoss=0.456
[Epoch 14] Validation: motorbike=0.7709298345517758 mAP=0.7709298345517758
[Epoch 15] Training cost: 3.618, ObjLoss=5.393,BoxCenterLoss=3.506,BoxScaleLoss=1.080,ClassLoss=0.507
[Epoch 15] Validation: motorbike=0.7582567501775981 mAP=0.7582567501775981
[Epoch 16] Training cost: 4.873, ObjLoss=5.179,BoxCenterLoss=3.499,BoxScaleLoss=0.924,ClassLoss=0.356
[Epoch 16] Validation: motorbike=0.7998728084902875 mAP=0.7998728084902875
[Epoch 17] Training cost: 4.232, ObjLoss=5.036,BoxCenterLoss=3.567,BoxScaleLoss=0.929,ClassLoss=0.404
[Epoch 17] Validation: motorbike=0.8164325164325166 mAP=0.8164325164325166
[Epoch 18] Training cost: 4.451, ObjLoss=4.512,BoxCenterLoss=3.373,BoxScaleLoss=0.923,ClassLoss=0.348
[Epoch 18] Validation: motorbike=0.8079136905874874 mAP=0.8079136905874874
[Epoch 19] Training cost: 3.711, ObjLoss=4.804,BoxCenterLoss=3.616,BoxScaleLoss=1.080,ClassLoss=0.452
[Epoch 19] Validation: motorbike=0.7692307692307693 mAP=0.7692307692307693
[Epoch 20] Training cost: 4.999, ObjLoss=4.729,BoxCenterLoss=3.502,BoxScaleLoss=0.843,ClassLoss=0.346
[Epoch 20] Validation: motorbike=0.8441505475162407 mAP=0.8441505475162407
[Epoch 21] Training cost: 6.937, ObjLoss=5.762,BoxCenterLoss=3.744,BoxScaleLoss=0.978,ClassLoss=0.341
[Epoch 21] Validation: motorbike=0.77088350246245 mAP=0.77088350246245
[Epoch 22] Training cost: 5.032, ObjLoss=4.856,BoxCenterLoss=3.325,BoxScaleLoss=0.828,ClassLoss=0.284
[Epoch 22] Validation: motorbike=0.8347277722277722 mAP=0.8347277722277722
[Epoch 23] Training cost: 7.808, ObjLoss=5.410,BoxCenterLoss=3.613,BoxScaleLoss=0.930,ClassLoss=0.282
[Epoch 23] Validation: motorbike=0.7824642529187984 mAP=0.7824642529187984
[Epoch 24] Training cost: 5.560, ObjLoss=4.834,BoxCenterLoss=3.724,BoxScaleLoss=0.819,ClassLoss=0.297
[Epoch 24] Validation: motorbike=0.8274593183419822 mAP=0.8274593183419822
[Epoch 25] Training cost: 7.141, ObjLoss=5.477,BoxCenterLoss=3.578,BoxScaleLoss=0.853,ClassLoss=0.273
[Epoch 25] Validation: motorbike=0.825699684592965 mAP=0.825699684592965
[Epoch 26] Training cost: 6.594, ObjLoss=5.218,BoxCenterLoss=3.709,BoxScaleLoss=0.868,ClassLoss=0.273
[Epoch 26] Validation: motorbike=0.8411871642849905 mAP=0.8411871642849905
[Epoch 27] Training cost: 4.732, ObjLoss=4.412,BoxCenterLoss=3.519,BoxScaleLoss=1.016,ClassLoss=0.283
[Epoch 27] Validation: motorbike=0.8474463113386 mAP=0.8474463113386
[Epoch 28] Training cost: 4.946, ObjLoss=4.499,BoxCenterLoss=3.608,BoxScaleLoss=0.851,ClassLoss=0.267
[Epoch 28] Validation: motorbike=0.8028245534190466 mAP=0.8028245534190466
[Epoch 29] Training cost: 4.144, ObjLoss=4.673,BoxCenterLoss=3.531,BoxScaleLoss=0.931,ClassLoss=0.301
[Epoch 29] Validation: motorbike=0.8224450228692008 mAP=0.8224450228692008
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f5d49d8d790>, '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': 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.590, ObjLoss=599.348,BoxCenterLoss=3.701,BoxScaleLoss=2.500,ClassLoss=0.911
[Epoch 1] Training cost: 5.413, ObjLoss=13.375,BoxCenterLoss=3.629,BoxScaleLoss=1.370,ClassLoss=0.734
[Epoch 2] Training cost: 6.165, ObjLoss=10.446,BoxCenterLoss=3.730,BoxScaleLoss=1.175,ClassLoss=0.590
[Epoch 3] Training cost: 8.715, ObjLoss=9.985,BoxCenterLoss=3.552,BoxScaleLoss=1.088,ClassLoss=0.408
[Epoch 4] Training cost: 5.205, ObjLoss=13.306,BoxCenterLoss=3.719,BoxScaleLoss=1.184,ClassLoss=0.470
[Epoch 5] Training cost: 7.433, ObjLoss=5.962,BoxCenterLoss=3.684,BoxScaleLoss=0.981,ClassLoss=0.327
[Epoch 6] Training cost: 7.389, ObjLoss=5.485,BoxCenterLoss=3.281,BoxScaleLoss=0.823,ClassLoss=0.238
[Epoch 7] Training cost: 4.898, ObjLoss=5.675,BoxCenterLoss=3.569,BoxScaleLoss=0.931,ClassLoss=0.358
[Epoch 8] Training cost: 7.369, ObjLoss=5.784,BoxCenterLoss=3.776,BoxScaleLoss=0.900,ClassLoss=0.264
[Epoch 9] Training cost: 6.597, ObjLoss=4.822,BoxCenterLoss=3.425,BoxScaleLoss=0.856,ClassLoss=0.205
[Epoch 10] Training cost: 4.712, ObjLoss=4.896,BoxCenterLoss=3.541,BoxScaleLoss=0.961,ClassLoss=0.242
[Epoch 11] Training cost: 6.218, ObjLoss=6.996,BoxCenterLoss=3.486,BoxScaleLoss=0.930,ClassLoss=0.214
[Epoch 12] Training cost: 6.257, ObjLoss=7.177,BoxCenterLoss=3.514,BoxScaleLoss=0.935,ClassLoss=0.215
[Epoch 13] Training cost: 8.432, ObjLoss=6.089,BoxCenterLoss=3.460,BoxScaleLoss=1.022,ClassLoss=0.184
[Epoch 14] Training cost: 7.048, ObjLoss=5.869,BoxCenterLoss=3.543,BoxScaleLoss=0.994,ClassLoss=0.188
[Epoch 15] Training cost: 5.769, ObjLoss=8.463,BoxCenterLoss=3.376,BoxScaleLoss=0.835,ClassLoss=0.218
[Epoch 16] Training cost: 4.097, ObjLoss=6.808,BoxCenterLoss=3.504,BoxScaleLoss=0.934,ClassLoss=0.240
[Epoch 17] Training cost: 4.354, ObjLoss=4.191,BoxCenterLoss=3.364,BoxScaleLoss=0.757,ClassLoss=0.205
[Epoch 18] Training cost: 8.174, ObjLoss=5.168,BoxCenterLoss=3.444,BoxScaleLoss=1.048,ClassLoss=0.127
[Epoch 19] Training cost: 4.384, ObjLoss=4.588,BoxCenterLoss=3.544,BoxScaleLoss=0.975,ClassLoss=0.191
[Epoch 20] Training cost: 5.827, ObjLoss=4.104,BoxCenterLoss=3.403,BoxScaleLoss=0.945,ClassLoss=0.162
[Epoch 21] Training cost: 6.000, ObjLoss=4.284,BoxCenterLoss=3.567,BoxScaleLoss=0.911,ClassLoss=0.164
[Epoch 22] Training cost: 5.906, ObjLoss=3.539,BoxCenterLoss=3.318,BoxScaleLoss=0.842,ClassLoss=0.151
[Epoch 23] Training cost: 5.603, ObjLoss=3.485,BoxCenterLoss=3.393,BoxScaleLoss=0.772,ClassLoss=0.123
[Epoch 24] Training cost: 6.867, ObjLoss=3.900,BoxCenterLoss=3.256,BoxScaleLoss=0.760,ClassLoss=0.112
[Epoch 25] Training cost: 8.204, ObjLoss=3.813,BoxCenterLoss=3.464,BoxScaleLoss=0.740,ClassLoss=0.113
[Epoch 26] Training cost: 6.083, ObjLoss=3.660,BoxCenterLoss=3.561,BoxScaleLoss=0.759,ClassLoss=0.120
[Epoch 27] Training cost: 6.463, ObjLoss=4.155,BoxCenterLoss=3.311,BoxScaleLoss=0.729,ClassLoss=0.122
[Epoch 28] Training cost: 8.544, ObjLoss=4.612,BoxCenterLoss=3.379,BoxScaleLoss=0.736,ClassLoss=0.099
[Epoch 29] Training cost: 4.571, ObjLoss=4.205,BoxCenterLoss=3.356,BoxScaleLoss=0.757,ClassLoss=0.136
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> finish model fitting
The best config: {'lr▁choice': 0, '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_14/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.8435792935792937

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)