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, 31807.89KB/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/453/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 0x7fe0ec954490>, '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.659, ObjLoss=1357.430,BoxCenterLoss=3.892,BoxScaleLoss=2.588,ClassLoss=1.052
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 5.029, ObjLoss=35.335,BoxCenterLoss=3.832,BoxScaleLoss=1.508,ClassLoss=0.791
[Epoch 1] Validation: motorbike=0.38490113490113487 mAP=0.38490113490113487
[Epoch 2] Training cost: 4.734, ObjLoss=27.803,BoxCenterLoss=3.990,BoxScaleLoss=1.297,ClassLoss=0.719
[Epoch 2] Validation: motorbike=0.09260803853525369 mAP=0.09260803853525369
[Epoch 3] Training cost: 4.929, ObjLoss=18.697,BoxCenterLoss=3.622,BoxScaleLoss=1.075,ClassLoss=0.622
[Epoch 3] Validation: motorbike=0.18792883822264048 mAP=0.18792883822264048
[Epoch 4] Training cost: 2.814, ObjLoss=22.340,BoxCenterLoss=3.532,BoxScaleLoss=0.996,ClassLoss=0.605
[Epoch 4] Validation: motorbike=0.599414250391816 mAP=0.599414250391816
[Epoch 5] Training cost: 3.775, ObjLoss=10.879,BoxCenterLoss=3.717,BoxScaleLoss=1.042,ClassLoss=0.497
[Epoch 5] Validation: motorbike=0.7213809799103917 mAP=0.7213809799103917
[Epoch 6] Training cost: 3.822, ObjLoss=10.759,BoxCenterLoss=3.913,BoxScaleLoss=1.179,ClassLoss=0.488
[Epoch 6] Validation: motorbike=0.652386536253813 mAP=0.652386536253813
[Epoch 7] Training cost: 6.169, ObjLoss=9.963,BoxCenterLoss=3.679,BoxScaleLoss=0.903,ClassLoss=0.384
[Epoch 7] Validation: motorbike=0.5409188590722204 mAP=0.5409188590722204
[Epoch 8] Training cost: 4.365, ObjLoss=10.884,BoxCenterLoss=3.799,BoxScaleLoss=0.960,ClassLoss=0.381
[Epoch 8] Validation: motorbike=0.6971499089146149 mAP=0.6971499089146149
[Epoch 9] Training cost: 3.092, ObjLoss=16.523,BoxCenterLoss=3.768,BoxScaleLoss=1.065,ClassLoss=0.497
[Epoch 9] Validation: motorbike=0.7191247963732245 mAP=0.7191247963732245
[Epoch 10] Training cost: 2.985, ObjLoss=7.906,BoxCenterLoss=3.628,BoxScaleLoss=0.902,ClassLoss=0.400
[Epoch 10] Validation: motorbike=0.698673625699689 mAP=0.698673625699689
[Epoch 11] Training cost: 3.427, ObjLoss=11.081,BoxCenterLoss=3.627,BoxScaleLoss=0.901,ClassLoss=0.395
[Epoch 11] Validation: motorbike=0.649848028875477 mAP=0.649848028875477
[Epoch 12] Training cost: 3.657, ObjLoss=10.187,BoxCenterLoss=3.681,BoxScaleLoss=0.861,ClassLoss=0.330
[Epoch 12] Validation: motorbike=0.7571610393222743 mAP=0.7571610393222743
[Epoch 13] Training cost: 6.396, ObjLoss=8.770,BoxCenterLoss=3.736,BoxScaleLoss=0.885,ClassLoss=0.269
[Epoch 13] Validation: motorbike=0.8042800305450907 mAP=0.8042800305450907
[Epoch 14] Training cost: 4.534, ObjLoss=6.227,BoxCenterLoss=3.562,BoxScaleLoss=0.712,ClassLoss=0.231
[Epoch 14] Validation: motorbike=0.8003748939232809 mAP=0.8003748939232809
[Epoch 15] Training cost: 3.616, ObjLoss=7.829,BoxCenterLoss=3.626,BoxScaleLoss=1.006,ClassLoss=0.320
[Epoch 15] Validation: motorbike=0.7626820014463035 mAP=0.7626820014463035
[Epoch 16] Training cost: 3.209, ObjLoss=11.817,BoxCenterLoss=3.826,BoxScaleLoss=1.015,ClassLoss=0.327
[Epoch 16] Validation: motorbike=0.7500453266117635 mAP=0.7500453266117635
[Epoch 17] Training cost: 3.396, ObjLoss=9.183,BoxCenterLoss=3.474,BoxScaleLoss=0.789,ClassLoss=0.260
[Epoch 17] Validation: motorbike=0.7640226433329882 mAP=0.7640226433329882
[Epoch 18] Training cost: 3.772, ObjLoss=8.721,BoxCenterLoss=3.720,BoxScaleLoss=0.978,ClassLoss=0.289
[Epoch 18] Validation: motorbike=0.7110327915413979 mAP=0.7110327915413979
[Epoch 19] Training cost: 2.939, ObjLoss=6.953,BoxCenterLoss=3.623,BoxScaleLoss=0.990,ClassLoss=0.327
[Epoch 19] Validation: motorbike=0.7589621120992227 mAP=0.7589621120992227
[Epoch 20] Training cost: 4.706, ObjLoss=5.967,BoxCenterLoss=3.695,BoxScaleLoss=0.990,ClassLoss=0.258
[Epoch 20] Validation: motorbike=0.7439025631812192 mAP=0.7439025631812192
[Epoch 21] Training cost: 4.398, ObjLoss=4.753,BoxCenterLoss=3.376,BoxScaleLoss=0.795,ClassLoss=0.199
[Epoch 21] Validation: motorbike=0.8131153796976581 mAP=0.8131153796976581
[Epoch 22] Training cost: 3.442, ObjLoss=4.626,BoxCenterLoss=3.539,BoxScaleLoss=0.821,ClassLoss=0.236
[Epoch 22] Validation: motorbike=0.8121271388408486 mAP=0.8121271388408486
[Epoch 23] Training cost: 7.371, ObjLoss=5.805,BoxCenterLoss=3.629,BoxScaleLoss=1.012,ClassLoss=0.159
[Epoch 23] Validation: motorbike=0.7021634813245775 mAP=0.7021634813245775
[Epoch 24] Training cost: 5.099, ObjLoss=4.886,BoxCenterLoss=3.577,BoxScaleLoss=0.878,ClassLoss=0.197
[Epoch 24] Validation: motorbike=0.7430959844752948 mAP=0.7430959844752948
[Epoch 25] Training cost: 3.459, ObjLoss=4.692,BoxCenterLoss=3.301,BoxScaleLoss=0.897,ClassLoss=0.199
[Epoch 25] Validation: motorbike=0.7758651026392961 mAP=0.7758651026392961
[Epoch 26] Training cost: 2.855, ObjLoss=4.683,BoxCenterLoss=3.636,BoxScaleLoss=0.853,ClassLoss=0.278
[Epoch 26] Validation: motorbike=0.8363114211641562 mAP=0.8363114211641562
[Epoch 27] Training cost: 4.770, ObjLoss=4.647,BoxCenterLoss=3.524,BoxScaleLoss=0.812,ClassLoss=0.186
[Epoch 27] Validation: motorbike=0.8066859066859069 mAP=0.8066859066859069
[Epoch 28] Training cost: 7.049, ObjLoss=5.816,BoxCenterLoss=3.744,BoxScaleLoss=0.965,ClassLoss=0.164
[Epoch 28] Validation: motorbike=0.7547162407004521 mAP=0.7547162407004521
[Epoch 29] Training cost: 6.252, ObjLoss=4.778,BoxCenterLoss=3.446,BoxScaleLoss=0.823,ClassLoss=0.144
[Epoch 29] Validation: motorbike=0.7737308993444293 mAP=0.7737308993444293
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7fe043a77250>, '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.684, ObjLoss=1465.454,BoxCenterLoss=3.960,BoxScaleLoss=2.979,ClassLoss=1.062
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 5.042, ObjLoss=20.225,BoxCenterLoss=3.851,BoxScaleLoss=2.136,ClassLoss=0.901
[Epoch 1] Validation: motorbike=0.0 mAP=0.0
[Epoch 2] Training cost: 4.827, ObjLoss=18.545,BoxCenterLoss=3.842,BoxScaleLoss=1.703,ClassLoss=0.810
[Epoch 2] Validation: motorbike=0.09090909090909091 mAP=0.09090909090909091
[Epoch 3] Training cost: 4.898, ObjLoss=13.397,BoxCenterLoss=3.738,BoxScaleLoss=1.487,ClassLoss=0.732
[Epoch 3] Validation: motorbike=0.37986028127585253 mAP=0.37986028127585253
[Epoch 4] Training cost: 2.718, ObjLoss=11.430,BoxCenterLoss=3.733,BoxScaleLoss=1.512,ClassLoss=0.802
[Epoch 4] Validation: motorbike=0.4191668764903351 mAP=0.4191668764903351
[Epoch 5] Training cost: 3.928, ObjLoss=8.220,BoxCenterLoss=3.824,BoxScaleLoss=1.342,ClassLoss=0.711
[Epoch 5] Validation: motorbike=0.46913516381865744 mAP=0.46913516381865744
[Epoch 6] Training cost: 3.919, ObjLoss=7.069,BoxCenterLoss=3.848,BoxScaleLoss=1.326,ClassLoss=0.698
[Epoch 6] Validation: motorbike=0.5426493464476352 mAP=0.5426493464476352
[Epoch 7] Training cost: 6.461, ObjLoss=7.329,BoxCenterLoss=3.890,BoxScaleLoss=1.174,ClassLoss=0.576
[Epoch 7] Validation: motorbike=0.5978334137311494 mAP=0.5978334137311494
[Epoch 8] Training cost: 4.625, ObjLoss=6.563,BoxCenterLoss=3.737,BoxScaleLoss=1.043,ClassLoss=0.540
[Epoch 8] Validation: motorbike=0.56324943476013 mAP=0.56324943476013
[Epoch 9] Training cost: 3.095, ObjLoss=6.979,BoxCenterLoss=3.708,BoxScaleLoss=1.056,ClassLoss=0.630
[Epoch 9] Validation: motorbike=0.664990532169716 mAP=0.664990532169716
[Epoch 10] Training cost: 2.920, ObjLoss=5.963,BoxCenterLoss=3.652,BoxScaleLoss=1.123,ClassLoss=0.596
[Epoch 10] Validation: motorbike=0.6684147076552139 mAP=0.6684147076552139
[Epoch 11] Training cost: 3.510, ObjLoss=5.705,BoxCenterLoss=3.765,BoxScaleLoss=1.003,ClassLoss=0.538
[Epoch 11] Validation: motorbike=0.6978840706113433 mAP=0.6978840706113433
[Epoch 12] Training cost: 3.747, ObjLoss=5.483,BoxCenterLoss=3.738,BoxScaleLoss=0.971,ClassLoss=0.474
[Epoch 12] Validation: motorbike=0.7585933399759008 mAP=0.7585933399759008
[Epoch 13] Training cost: 6.529, ObjLoss=5.801,BoxCenterLoss=3.613,BoxScaleLoss=1.003,ClassLoss=0.405
[Epoch 13] Validation: motorbike=0.7498584161654145 mAP=0.7498584161654145
[Epoch 14] Training cost: 4.494, ObjLoss=5.169,BoxCenterLoss=3.679,BoxScaleLoss=0.977,ClassLoss=0.385
[Epoch 14] Validation: motorbike=0.7596170303743698 mAP=0.7596170303743698
[Epoch 15] Training cost: 3.454, ObjLoss=5.615,BoxCenterLoss=3.723,BoxScaleLoss=1.060,ClassLoss=0.471
[Epoch 15] Validation: motorbike=0.7323532799061745 mAP=0.7323532799061745
[Epoch 16] Training cost: 3.333, ObjLoss=4.883,BoxCenterLoss=3.578,BoxScaleLoss=0.999,ClassLoss=0.427
[Epoch 16] Validation: motorbike=0.8041550405199277 mAP=0.8041550405199277
[Epoch 17] Training cost: 3.753, ObjLoss=5.130,BoxCenterLoss=3.636,BoxScaleLoss=1.004,ClassLoss=0.440
[Epoch 17] Validation: motorbike=0.7681838858309447 mAP=0.7681838858309447
[Epoch 18] Training cost: 3.845, ObjLoss=5.184,BoxCenterLoss=3.789,BoxScaleLoss=0.950,ClassLoss=0.401
[Epoch 18] Validation: motorbike=0.7714859703094998 mAP=0.7714859703094998
[Epoch 19] Training cost: 2.966, ObjLoss=5.371,BoxCenterLoss=3.639,BoxScaleLoss=1.010,ClassLoss=0.428
[Epoch 19] Validation: motorbike=0.7651053308948047 mAP=0.7651053308948047
[Epoch 20] Training cost: 4.749, ObjLoss=5.194,BoxCenterLoss=3.824,BoxScaleLoss=0.988,ClassLoss=0.349
[Epoch 20] Validation: motorbike=0.7090207840995548 mAP=0.7090207840995548
[Epoch 21] Training cost: 4.502, ObjLoss=5.270,BoxCenterLoss=3.718,BoxScaleLoss=0.924,ClassLoss=0.370
[Epoch 21] Validation: motorbike=0.8321147689711763 mAP=0.8321147689711763
[Epoch 22] Training cost: 3.661, ObjLoss=5.448,BoxCenterLoss=3.815,BoxScaleLoss=0.937,ClassLoss=0.398
[Epoch 22] Validation: motorbike=0.8413171120067672 mAP=0.8413171120067672
[Epoch 23] Training cost: 7.612, ObjLoss=5.969,BoxCenterLoss=3.686,BoxScaleLoss=0.977,ClassLoss=0.260
[Epoch 23] Validation: motorbike=0.8037946807065289 mAP=0.8037946807065289
[Epoch 24] Training cost: 5.188, ObjLoss=4.985,BoxCenterLoss=3.646,BoxScaleLoss=0.947,ClassLoss=0.255
[Epoch 24] Validation: motorbike=0.8143498439150613 mAP=0.8143498439150613
[Epoch 25] Training cost: 3.611, ObjLoss=4.508,BoxCenterLoss=3.465,BoxScaleLoss=0.903,ClassLoss=0.310
[Epoch 25] Validation: motorbike=0.8188375447903579 mAP=0.8188375447903579
[Epoch 26] Training cost: 3.152, ObjLoss=4.708,BoxCenterLoss=3.647,BoxScaleLoss=0.923,ClassLoss=0.344
[Epoch 26] Validation: motorbike=0.7706478297239522 mAP=0.7706478297239522
[Epoch 27] Training cost: 5.015, ObjLoss=4.459,BoxCenterLoss=3.536,BoxScaleLoss=0.824,ClassLoss=0.271
[Epoch 27] Validation: motorbike=0.842709832540341 mAP=0.842709832540341
[Epoch 28] Training cost: 6.995, ObjLoss=5.204,BoxCenterLoss=3.673,BoxScaleLoss=0.829,ClassLoss=0.223
[Epoch 28] Validation: motorbike=0.8313423466638241 mAP=0.8313423466638241
[Epoch 29] Training cost: 6.462, ObjLoss=4.550,BoxCenterLoss=3.585,BoxScaleLoss=0.838,ClassLoss=0.230
[Epoch 29] Validation: motorbike=0.8040361836682056 mAP=0.8040361836682056
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7fe043997c10>, '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.749, ObjLoss=713.875,BoxCenterLoss=3.817,BoxScaleLoss=2.872,ClassLoss=1.075
[Epoch 1] Training cost: 4.907, ObjLoss=14.552,BoxCenterLoss=3.710,BoxScaleLoss=1.984,ClassLoss=0.881
[Epoch 2] Training cost: 5.971, ObjLoss=13.565,BoxCenterLoss=3.892,BoxScaleLoss=1.734,ClassLoss=0.747
[Epoch 3] Training cost: 9.282, ObjLoss=10.178,BoxCenterLoss=3.648,BoxScaleLoss=1.456,ClassLoss=0.659
[Epoch 4] Training cost: 4.753, ObjLoss=7.574,BoxCenterLoss=3.699,BoxScaleLoss=1.402,ClassLoss=0.695
[Epoch 5] Training cost: 7.312, ObjLoss=6.991,BoxCenterLoss=3.755,BoxScaleLoss=1.221,ClassLoss=0.539
[Epoch 6] Training cost: 7.434, ObjLoss=6.300,BoxCenterLoss=3.391,BoxScaleLoss=1.157,ClassLoss=0.446
[Epoch 7] Training cost: 4.580, ObjLoss=6.629,BoxCenterLoss=3.623,BoxScaleLoss=1.279,ClassLoss=0.533
[Epoch 8] Training cost: 7.216, ObjLoss=6.426,BoxCenterLoss=3.870,BoxScaleLoss=1.190,ClassLoss=0.478
[Epoch 9] Training cost: 5.995, ObjLoss=5.853,BoxCenterLoss=3.580,BoxScaleLoss=1.003,ClassLoss=0.442
[Epoch 10] Training cost: 4.512, ObjLoss=5.187,BoxCenterLoss=3.453,BoxScaleLoss=1.036,ClassLoss=0.446
[Epoch 11] Training cost: 5.718, ObjLoss=5.486,BoxCenterLoss=3.610,BoxScaleLoss=1.056,ClassLoss=0.419
[Epoch 12] Training cost: 6.078, ObjLoss=5.592,BoxCenterLoss=3.721,BoxScaleLoss=1.028,ClassLoss=0.416
[Epoch 13] Training cost: 8.267, ObjLoss=5.838,BoxCenterLoss=3.513,BoxScaleLoss=0.962,ClassLoss=0.275
[Epoch 14] Training cost: 6.585, ObjLoss=5.635,BoxCenterLoss=3.556,BoxScaleLoss=0.993,ClassLoss=0.339
[Epoch 15] Training cost: 4.990, ObjLoss=5.077,BoxCenterLoss=3.713,BoxScaleLoss=1.024,ClassLoss=0.349
[Epoch 16] Training cost: 3.780, ObjLoss=5.097,BoxCenterLoss=3.571,BoxScaleLoss=0.980,ClassLoss=0.410
[Epoch 17] Training cost: 3.621, ObjLoss=4.829,BoxCenterLoss=3.511,BoxScaleLoss=0.997,ClassLoss=0.369
[Epoch 18] Training cost: 7.354, ObjLoss=5.432,BoxCenterLoss=3.726,BoxScaleLoss=0.932,ClassLoss=0.269
[Epoch 19] Training cost: 3.636, ObjLoss=4.865,BoxCenterLoss=3.647,BoxScaleLoss=0.934,ClassLoss=0.353
[Epoch 20] Training cost: 5.128, ObjLoss=4.670,BoxCenterLoss=3.564,BoxScaleLoss=0.915,ClassLoss=0.311
[Epoch 21] Training cost: 5.883, ObjLoss=4.426,BoxCenterLoss=3.539,BoxScaleLoss=0.919,ClassLoss=0.257
[Epoch 22] Training cost: 5.176, ObjLoss=4.634,BoxCenterLoss=3.516,BoxScaleLoss=0.899,ClassLoss=0.268
[Epoch 23] Training cost: 5.192, ObjLoss=4.061,BoxCenterLoss=3.335,BoxScaleLoss=0.836,ClassLoss=0.242
[Epoch 24] Training cost: 5.992, ObjLoss=4.685,BoxCenterLoss=3.422,BoxScaleLoss=0.877,ClassLoss=0.228
[Epoch 25] Training cost: 7.769, ObjLoss=4.732,BoxCenterLoss=3.569,BoxScaleLoss=0.815,ClassLoss=0.218
[Epoch 26] Training cost: 5.473, ObjLoss=4.368,BoxCenterLoss=3.507,BoxScaleLoss=0.889,ClassLoss=0.219
[Epoch 27] Training cost: 5.908, ObjLoss=4.054,BoxCenterLoss=3.334,BoxScaleLoss=0.776,ClassLoss=0.184
[Epoch 28] Training cost: 7.938, ObjLoss=4.771,BoxCenterLoss=3.298,BoxScaleLoss=0.900,ClassLoss=0.167
[Epoch 29] Training cost: 4.161, ObjLoss=4.445,BoxCenterLoss=3.440,BoxScaleLoss=1.045,ClassLoss=0.249
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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.670372692441658

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)