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 YOLO3 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)
Downloading ./tiny_motorbike.zip from https://autogluon.s3.amazonaws.com/datasets/tiny_motorbike.zip...
21273KB [00:00, 66481.80KB/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 YOLO3 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 epoches.

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.45.231/22332/1' processes=1 threads=8, memory=33.24 GB>, Resource: NodeResourceManager(8 CPUs, 1 GPUs))
})
HBox(children=(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 0x7f4f4071c5d0>, '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: 4.077, ObjLoss=1185.100,BoxCenterLoss=4.059,BoxScaleLoss=2.554,ClassLoss=1.016
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 3.437, ObjLoss=25.579,BoxCenterLoss=3.498,BoxScaleLoss=1.536,ClassLoss=0.744
[Epoch 1] Validation: motorbike=0.6032007468051548 mAP=0.6032007468051548
[Epoch 2] Training cost: 3.597, ObjLoss=17.876,BoxCenterLoss=3.537,BoxScaleLoss=1.262,ClassLoss=0.638
[Epoch 2] Validation: motorbike=0.4826580254046405 mAP=0.4826580254046405
[Epoch 3] Training cost: 4.989, ObjLoss=9.069,BoxCenterLoss=3.699,BoxScaleLoss=1.214,ClassLoss=0.563
[Epoch 3] Validation: motorbike=0.2044071021448962 mAP=0.2044071021448962
[Epoch 4] Training cost: 6.951, ObjLoss=7.971,BoxCenterLoss=3.827,BoxScaleLoss=1.204,ClassLoss=0.489
[Epoch 4] Validation: motorbike=0.7108268202385848 mAP=0.7108268202385848
[Epoch 5] Training cost: 6.079, ObjLoss=10.144,BoxCenterLoss=3.686,BoxScaleLoss=1.084,ClassLoss=0.409
[Epoch 5] Validation: motorbike=0.7220810116969992 mAP=0.7220810116969992
[Epoch 6] Training cost: 4.137, ObjLoss=30.361,BoxCenterLoss=3.673,BoxScaleLoss=1.056,ClassLoss=0.465
[Epoch 6] Validation: motorbike=0.274060779697167 mAP=0.274060779697167
[Epoch 7] Training cost: 4.928, ObjLoss=21.534,BoxCenterLoss=3.544,BoxScaleLoss=0.990,ClassLoss=0.386
[Epoch 7] Validation: motorbike=0.7130636508626939 mAP=0.7130636508626939
[Epoch 8] Training cost: 6.727, ObjLoss=18.434,BoxCenterLoss=3.713,BoxScaleLoss=1.150,ClassLoss=0.357
[Epoch 8] Validation: motorbike=0.8058412176059236 mAP=0.8058412176059236
[Epoch 9] Training cost: 3.734, ObjLoss=19.954,BoxCenterLoss=3.693,BoxScaleLoss=1.152,ClassLoss=0.373
[Epoch 9] Validation: motorbike=0.5062637467026181 mAP=0.5062637467026181
[Epoch 10] Training cost: 4.983, ObjLoss=9.360,BoxCenterLoss=3.627,BoxScaleLoss=0.938,ClassLoss=0.306
[Epoch 10] Validation: motorbike=0.8111888111888114 mAP=0.8111888111888114
[Epoch 11] Training cost: 3.584, ObjLoss=20.134,BoxCenterLoss=3.455,BoxScaleLoss=1.021,ClassLoss=0.357
[Epoch 11] Validation: motorbike=0.8433204726308176 mAP=0.8433204726308176
[Epoch 12] Training cost: 4.570, ObjLoss=17.158,BoxCenterLoss=3.604,BoxScaleLoss=0.957,ClassLoss=0.295
[Epoch 12] Validation: motorbike=0.7913096482062001 mAP=0.7913096482062001
[Epoch 13] Training cost: 3.282, ObjLoss=12.709,BoxCenterLoss=3.680,BoxScaleLoss=1.167,ClassLoss=0.404
[Epoch 13] Validation: motorbike=0.8311206035343968 mAP=0.8311206035343968
[Epoch 14] Training cost: 2.922, ObjLoss=10.534,BoxCenterLoss=3.674,BoxScaleLoss=1.133,ClassLoss=0.393
[Epoch 14] Validation: motorbike=0.8240164805954279 mAP=0.8240164805954279
[Epoch 15] Training cost: 4.792, ObjLoss=6.729,BoxCenterLoss=3.657,BoxScaleLoss=0.964,ClassLoss=0.294
[Epoch 15] Validation: motorbike=0.7726754447890978 mAP=0.7726754447890978
[Epoch 16] Training cost: 6.415, ObjLoss=6.257,BoxCenterLoss=3.813,BoxScaleLoss=0.951,ClassLoss=0.258
[Epoch 16] Validation: motorbike=0.6770277820006081 mAP=0.6770277820006081
[Epoch 17] Training cost: 5.467, ObjLoss=5.506,BoxCenterLoss=3.455,BoxScaleLoss=0.924,ClassLoss=0.198
[Epoch 17] Validation: motorbike=0.8391931231906327 mAP=0.8391931231906327
[Epoch 18] Training cost: 2.731, ObjLoss=6.768,BoxCenterLoss=3.503,BoxScaleLoss=0.979,ClassLoss=0.290
[Epoch 18] Validation: motorbike=0.8222404389868504 mAP=0.8222404389868504
[Epoch 19] Training cost: 6.287, ObjLoss=6.359,BoxCenterLoss=3.595,BoxScaleLoss=0.998,ClassLoss=0.178
[Epoch 19] Validation: motorbike=0.8530808086526561 mAP=0.8530808086526561
[Epoch 20] Training cost: 6.554, ObjLoss=5.882,BoxCenterLoss=3.508,BoxScaleLoss=0.911,ClassLoss=0.183
[Epoch 20] Validation: motorbike=0.8235605831800334 mAP=0.8235605831800334
[Epoch 21] Training cost: 7.159, ObjLoss=5.541,BoxCenterLoss=3.573,BoxScaleLoss=0.853,ClassLoss=0.160
[Epoch 21] Validation: motorbike=0.8667301342393876 mAP=0.8667301342393876
[Epoch 22] Training cost: 5.807, ObjLoss=4.529,BoxCenterLoss=3.523,BoxScaleLoss=0.824,ClassLoss=0.169
[Epoch 22] Validation: motorbike=0.8601731601731601 mAP=0.8601731601731601
[Epoch 23] Training cost: 3.186, ObjLoss=5.980,BoxCenterLoss=3.513,BoxScaleLoss=0.978,ClassLoss=0.285
[Epoch 23] Validation: motorbike=0.7326838904204632 mAP=0.7326838904204632
[Epoch 24] Training cost: 6.093, ObjLoss=5.527,BoxCenterLoss=3.327,BoxScaleLoss=0.830,ClassLoss=0.136
[Epoch 24] Validation: motorbike=0.8384466938683808 mAP=0.8384466938683808
[Epoch 25] Training cost: 4.281, ObjLoss=6.182,BoxCenterLoss=3.540,BoxScaleLoss=0.782,ClassLoss=0.199
[Epoch 25] Validation: motorbike=0.860577796620435 mAP=0.860577796620435
[Epoch 26] Training cost: 3.496, ObjLoss=5.699,BoxCenterLoss=3.596,BoxScaleLoss=0.910,ClassLoss=0.240
[Epoch 26] Validation: motorbike=0.8136363636363637 mAP=0.8136363636363637
[Epoch 27] Training cost: 4.789, ObjLoss=5.546,BoxCenterLoss=3.516,BoxScaleLoss=0.799,ClassLoss=0.181
[Epoch 27] Validation: motorbike=0.8950931487325665 mAP=0.8950931487325665
[Epoch 28] Training cost: 6.415, ObjLoss=6.117,BoxCenterLoss=3.583,BoxScaleLoss=0.818,ClassLoss=0.147
[Epoch 28] Validation: motorbike=0.8447490302141466 mAP=0.8447490302141466
[Epoch 29] Training cost: 2.916, ObjLoss=13.417,BoxCenterLoss=3.515,BoxScaleLoss=0.982,ClassLoss=0.277
[Epoch 29] Validation: motorbike=0.8302283504247039 mAP=0.8302283504247039
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f4f40739910>, '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: 4.331, ObjLoss=1303.873,BoxCenterLoss=4.174,BoxScaleLoss=3.108,ClassLoss=1.090
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 3.727, ObjLoss=17.706,BoxCenterLoss=3.623,BoxScaleLoss=2.072,ClassLoss=0.881
[Epoch 1] Validation: motorbike=0.0 mAP=0.0
[Epoch 2] Training cost: 3.907, ObjLoss=17.256,BoxCenterLoss=3.601,BoxScaleLoss=1.727,ClassLoss=0.792
[Epoch 2] Validation: motorbike=0.045454545454545456 mAP=0.045454545454545456
[Epoch 3] Training cost: 5.032, ObjLoss=13.802,BoxCenterLoss=3.636,BoxScaleLoss=1.482,ClassLoss=0.700
[Epoch 3] Validation: motorbike=0.3964511424404472 mAP=0.3964511424404472
[Epoch 4] Training cost: 6.918, ObjLoss=9.850,BoxCenterLoss=3.556,BoxScaleLoss=1.349,ClassLoss=0.651
[Epoch 4] Validation: motorbike=0.5112118138791567 mAP=0.5112118138791567
[Epoch 5] Training cost: 6.472, ObjLoss=7.720,BoxCenterLoss=3.603,BoxScaleLoss=1.256,ClassLoss=0.616
[Epoch 5] Validation: motorbike=0.46238548273432 mAP=0.46238548273432
[Epoch 6] Training cost: 4.495, ObjLoss=6.759,BoxCenterLoss=3.609,BoxScaleLoss=1.230,ClassLoss=0.633
[Epoch 6] Validation: motorbike=0.4360043233375069 mAP=0.4360043233375069
[Epoch 7] Training cost: 5.114, ObjLoss=7.434,BoxCenterLoss=3.659,BoxScaleLoss=1.248,ClassLoss=0.631
[Epoch 7] Validation: motorbike=0.643568931068931 mAP=0.643568931068931
[Epoch 8] Training cost: 7.169, ObjLoss=7.272,BoxCenterLoss=3.942,BoxScaleLoss=1.211,ClassLoss=0.573
[Epoch 8] Validation: motorbike=0.6817540058699278 mAP=0.6817540058699278
[Epoch 9] Training cost: 4.226, ObjLoss=6.177,BoxCenterLoss=3.636,BoxScaleLoss=1.128,ClassLoss=0.577
[Epoch 9] Validation: motorbike=0.738733240331706 mAP=0.738733240331706
[Epoch 10] Training cost: 5.188, ObjLoss=6.262,BoxCenterLoss=3.780,BoxScaleLoss=1.170,ClassLoss=0.505
[Epoch 10] Validation: motorbike=0.6962377560023741 mAP=0.6962377560023741
[Epoch 11] Training cost: 3.737, ObjLoss=5.992,BoxCenterLoss=3.465,BoxScaleLoss=1.081,ClassLoss=0.522
[Epoch 11] Validation: motorbike=0.7392273899206191 mAP=0.7392273899206191
[Epoch 12] Training cost: 4.957, ObjLoss=5.622,BoxCenterLoss=3.566,BoxScaleLoss=0.948,ClassLoss=0.447
[Epoch 12] Validation: motorbike=0.8217803461822601 mAP=0.8217803461822601
[Epoch 13] Training cost: 3.362, ObjLoss=5.868,BoxCenterLoss=3.513,BoxScaleLoss=1.001,ClassLoss=0.501
[Epoch 13] Validation: motorbike=0.8384592680047227 mAP=0.8384592680047227
[Epoch 14] Training cost: 3.026, ObjLoss=6.261,BoxCenterLoss=3.696,BoxScaleLoss=1.098,ClassLoss=0.531
[Epoch 14] Validation: motorbike=0.7614134647768422 mAP=0.7614134647768422
[Epoch 15] Training cost: 5.091, ObjLoss=5.234,BoxCenterLoss=3.553,BoxScaleLoss=0.974,ClassLoss=0.423
[Epoch 15] Validation: motorbike=0.8621557653815719 mAP=0.8621557653815719
[Epoch 16] Training cost: 6.271, ObjLoss=5.362,BoxCenterLoss=3.711,BoxScaleLoss=0.953,ClassLoss=0.353
[Epoch 16] Validation: motorbike=0.8721417926335961 mAP=0.8721417926335961
[Epoch 17] Training cost: 5.619, ObjLoss=5.469,BoxCenterLoss=3.573,BoxScaleLoss=0.940,ClassLoss=0.353
[Epoch 17] Validation: motorbike=0.8498287506246428 mAP=0.8498287506246428
[Epoch 18] Training cost: 2.705, ObjLoss=5.645,BoxCenterLoss=3.702,BoxScaleLoss=1.138,ClassLoss=0.453
[Epoch 18] Validation: motorbike=0.7753325942350334 mAP=0.7753325942350334
[Epoch 19] Training cost: 6.561, ObjLoss=5.515,BoxCenterLoss=3.810,BoxScaleLoss=0.926,ClassLoss=0.343
[Epoch 19] Validation: motorbike=0.8713557519527669 mAP=0.8713557519527669
[Epoch 20] Training cost: 6.978, ObjLoss=5.534,BoxCenterLoss=3.547,BoxScaleLoss=0.869,ClassLoss=0.269
[Epoch 20] Validation: motorbike=0.8635566188197766 mAP=0.8635566188197766
[Epoch 21] Training cost: 7.618, ObjLoss=5.686,BoxCenterLoss=3.694,BoxScaleLoss=0.953,ClassLoss=0.277
[Epoch 21] Validation: motorbike=0.8655979437229439 mAP=0.8655979437229439
[Epoch 22] Training cost: 6.043, ObjLoss=5.338,BoxCenterLoss=3.589,BoxScaleLoss=0.889,ClassLoss=0.301
[Epoch 22] Validation: motorbike=0.8443497474747474 mAP=0.8443497474747474
[Epoch 23] Training cost: 3.261, ObjLoss=5.130,BoxCenterLoss=3.479,BoxScaleLoss=0.950,ClassLoss=0.374
[Epoch 23] Validation: motorbike=0.8800249458144195 mAP=0.8800249458144195
[Epoch 24] Training cost: 6.467, ObjLoss=5.156,BoxCenterLoss=3.429,BoxScaleLoss=0.858,ClassLoss=0.235
[Epoch 24] Validation: motorbike=0.8371175640838563 mAP=0.8371175640838563
[Epoch 25] Training cost: 4.641, ObjLoss=5.015,BoxCenterLoss=3.788,BoxScaleLoss=1.026,ClassLoss=0.329
[Epoch 25] Validation: motorbike=0.8715203987931259 mAP=0.8715203987931259
[Epoch 26] Training cost: 3.375, ObjLoss=4.717,BoxCenterLoss=3.493,BoxScaleLoss=0.930,ClassLoss=0.341
[Epoch 26] Validation: motorbike=0.8885077186963981 mAP=0.8885077186963981
[Epoch 27] Training cost: 5.114, ObjLoss=4.767,BoxCenterLoss=3.664,BoxScaleLoss=0.909,ClassLoss=0.306
[Epoch 27] Validation: motorbike=0.8738127544097695 mAP=0.8738127544097695
[Epoch 28] Training cost: 6.553, ObjLoss=4.841,BoxCenterLoss=3.526,BoxScaleLoss=0.876,ClassLoss=0.250
[Epoch 28] Validation: motorbike=0.8685503685503687 mAP=0.8685503685503687
[Epoch 29] Training cost: 2.882, ObjLoss=5.292,BoxCenterLoss=3.557,BoxScaleLoss=0.990,ClassLoss=0.385
[Epoch 29] Validation: motorbike=0.8540336475119085 mAP=0.8540336475119085
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f4e6215d4d0>, '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: 3.613, ObjLoss=713.868,BoxCenterLoss=3.996,BoxScaleLoss=2.943,ClassLoss=1.077
[Epoch 1] Training cost: 4.795, ObjLoss=16.846,BoxCenterLoss=3.972,BoxScaleLoss=2.126,ClassLoss=0.889
[Epoch 2] Training cost: 5.986, ObjLoss=13.730,BoxCenterLoss=3.854,BoxScaleLoss=1.601,ClassLoss=0.763
[Epoch 3] Training cost: 8.971, ObjLoss=9.769,BoxCenterLoss=3.826,BoxScaleLoss=1.471,ClassLoss=0.661
[Epoch 4] Training cost: 4.795, ObjLoss=7.435,BoxCenterLoss=3.616,BoxScaleLoss=1.327,ClassLoss=0.656
[Epoch 5] Training cost: 7.502, ObjLoss=7.316,BoxCenterLoss=3.754,BoxScaleLoss=1.131,ClassLoss=0.575
[Epoch 6] Training cost: 7.441, ObjLoss=6.413,BoxCenterLoss=3.646,BoxScaleLoss=1.212,ClassLoss=0.475
[Epoch 7] Training cost: 4.546, ObjLoss=6.386,BoxCenterLoss=3.721,BoxScaleLoss=1.173,ClassLoss=0.570
[Epoch 8] Training cost: 7.511, ObjLoss=6.347,BoxCenterLoss=3.775,BoxScaleLoss=1.110,ClassLoss=0.493
[Epoch 9] Training cost: 6.258, ObjLoss=5.449,BoxCenterLoss=3.541,BoxScaleLoss=1.034,ClassLoss=0.414
[Epoch 10] Training cost: 4.643, ObjLoss=5.184,BoxCenterLoss=3.477,BoxScaleLoss=0.930,ClassLoss=0.403
[Epoch 11] Training cost: 5.761, ObjLoss=5.023,BoxCenterLoss=3.407,BoxScaleLoss=0.949,ClassLoss=0.359
[Epoch 12] Training cost: 6.162, ObjLoss=4.904,BoxCenterLoss=3.633,BoxScaleLoss=1.030,ClassLoss=0.381
[Epoch 13] Training cost: 8.310, ObjLoss=5.307,BoxCenterLoss=3.209,BoxScaleLoss=0.934,ClassLoss=0.263
[Epoch 14] Training cost: 6.318, ObjLoss=5.498,BoxCenterLoss=3.729,BoxScaleLoss=1.030,ClassLoss=0.361
[Epoch 15] Training cost: 5.012, ObjLoss=4.990,BoxCenterLoss=3.579,BoxScaleLoss=1.022,ClassLoss=0.364
[Epoch 16] Training cost: 3.822, ObjLoss=5.016,BoxCenterLoss=3.438,BoxScaleLoss=0.993,ClassLoss=0.355
[Epoch 17] Training cost: 3.981, ObjLoss=5.043,BoxCenterLoss=3.474,BoxScaleLoss=1.000,ClassLoss=0.365
[Epoch 18] Training cost: 7.345, ObjLoss=5.142,BoxCenterLoss=3.542,BoxScaleLoss=0.847,ClassLoss=0.261
[Epoch 19] Training cost: 3.863, ObjLoss=4.818,BoxCenterLoss=3.604,BoxScaleLoss=1.004,ClassLoss=0.386
[Epoch 20] Training cost: 5.212, ObjLoss=4.414,BoxCenterLoss=3.490,BoxScaleLoss=0.893,ClassLoss=0.311
[Epoch 21] Training cost: 5.799, ObjLoss=4.870,BoxCenterLoss=3.545,BoxScaleLoss=0.931,ClassLoss=0.284
[Epoch 22] Training cost: 5.322, ObjLoss=4.158,BoxCenterLoss=3.318,BoxScaleLoss=0.841,ClassLoss=0.245
[Epoch 23] Training cost: 5.247, ObjLoss=4.252,BoxCenterLoss=3.514,BoxScaleLoss=0.926,ClassLoss=0.263
[Epoch 24] Training cost: 6.099, ObjLoss=4.775,BoxCenterLoss=3.638,BoxScaleLoss=0.906,ClassLoss=0.246
[Epoch 25] Training cost: 7.743, ObjLoss=4.217,BoxCenterLoss=3.345,BoxScaleLoss=0.848,ClassLoss=0.172
[Epoch 26] Training cost: 5.432, ObjLoss=4.139,BoxCenterLoss=3.355,BoxScaleLoss=0.844,ClassLoss=0.203
[Epoch 27] Training cost: 5.970, ObjLoss=4.089,BoxCenterLoss=3.343,BoxScaleLoss=0.812,ClassLoss=0.218
[Epoch 28] Training cost: 8.089, ObjLoss=4.503,BoxCenterLoss=3.491,BoxScaleLoss=0.847,ClassLoss=0.191
[Epoch 29] Training cost: 4.213, ObjLoss=4.766,BoxCenterLoss=3.531,BoxScaleLoss=0.969,ClassLoss=0.269
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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]))
>>> create dataset(VOC format)
mAP on test dataset: 0.8234091995271439

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)