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)
Downloading ./tiny_motorbike.zip from https://autogluon.s3.amazonaws.com/datasets/tiny_motorbike.zip...
21273KB [00:00, 32010.32KB/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.45.231/21407/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 0x7f582bb7ab90>, '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: 5.301, ObjLoss=742.450,BoxCenterLoss=4.023,BoxScaleLoss=2.669,ClassLoss=0.983
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 6.406, ObjLoss=20.037,BoxCenterLoss=3.404,BoxScaleLoss=1.663,ClassLoss=0.720
[Epoch 1] Validation: motorbike=0.0 mAP=0.0
[Epoch 2] Training cost: 4.761, ObjLoss=23.922,BoxCenterLoss=3.617,BoxScaleLoss=1.335,ClassLoss=0.757
[Epoch 2] Validation: motorbike=0.01424768216263468 mAP=0.01424768216263468
[Epoch 3] Training cost: 2.975, ObjLoss=24.290,BoxCenterLoss=3.674,BoxScaleLoss=1.390,ClassLoss=0.673
[Epoch 3] Validation: motorbike=0.0 mAP=0.0
[Epoch 4] Training cost: 6.926, ObjLoss=11.893,BoxCenterLoss=3.481,BoxScaleLoss=1.304,ClassLoss=0.517
[Epoch 4] Validation: motorbike=0.0 mAP=0.0
[Epoch 5] Training cost: 6.899, ObjLoss=10.250,BoxCenterLoss=3.706,BoxScaleLoss=1.214,ClassLoss=0.435
[Epoch 5] Validation: motorbike=0.2628684305019411 mAP=0.2628684305019411
[Epoch 6] Training cost: 3.911, ObjLoss=9.794,BoxCenterLoss=3.753,BoxScaleLoss=1.208,ClassLoss=0.475
[Epoch 6] Validation: motorbike=0.08296509367264314 mAP=0.08296509367264314
[Epoch 7] Training cost: 4.115, ObjLoss=12.445,BoxCenterLoss=3.483,BoxScaleLoss=1.045,ClassLoss=0.420
[Epoch 7] Validation: motorbike=0.3918078298513081 mAP=0.3918078298513081
[Epoch 8] Training cost: 5.715, ObjLoss=12.344,BoxCenterLoss=3.625,BoxScaleLoss=1.097,ClassLoss=0.348
[Epoch 8] Validation: motorbike=0.4873482726423903 mAP=0.4873482726423903
[Epoch 9] Training cost: 5.958, ObjLoss=14.947,BoxCenterLoss=3.699,BoxScaleLoss=1.039,ClassLoss=0.383
[Epoch 9] Validation: motorbike=0.49751207925325147 mAP=0.49751207925325147
[Epoch 10] Training cost: 6.144, ObjLoss=9.529,BoxCenterLoss=3.551,BoxScaleLoss=0.933,ClassLoss=0.305
[Epoch 10] Validation: motorbike=0.5686214172674521 mAP=0.5686214172674521
[Epoch 11] Training cost: 7.491, ObjLoss=8.043,BoxCenterLoss=3.604,BoxScaleLoss=0.957,ClassLoss=0.266
[Epoch 11] Validation: motorbike=0.44231016871565293 mAP=0.44231016871565293
[Epoch 12] Training cost: 3.161, ObjLoss=9.165,BoxCenterLoss=3.703,BoxScaleLoss=1.073,ClassLoss=0.431
[Epoch 12] Validation: motorbike=0.5615212983043653 mAP=0.5615212983043653
[Epoch 13] Training cost: 3.976, ObjLoss=9.043,BoxCenterLoss=3.539,BoxScaleLoss=0.961,ClassLoss=0.380
[Epoch 13] Validation: motorbike=0.2838262782211159 mAP=0.2838262782211159
[Epoch 14] Training cost: 4.868, ObjLoss=6.830,BoxCenterLoss=3.564,BoxScaleLoss=0.949,ClassLoss=0.301
[Epoch 14] Validation: motorbike=0.3227807273208524 mAP=0.3227807273208524
[Epoch 15] Training cost: 7.256, ObjLoss=8.942,BoxCenterLoss=3.514,BoxScaleLoss=0.948,ClassLoss=0.253
[Epoch 15] Validation: motorbike=0.6481142506142507 mAP=0.6481142506142507
[Epoch 16] Training cost: 3.275, ObjLoss=7.666,BoxCenterLoss=3.380,BoxScaleLoss=0.918,ClassLoss=0.293
[Epoch 16] Validation: motorbike=0.6147668588641487 mAP=0.6147668588641487
[Epoch 17] Training cost: 7.659, ObjLoss=7.791,BoxCenterLoss=3.740,BoxScaleLoss=1.107,ClassLoss=0.242
[Epoch 17] Validation: motorbike=0.5788201160541587 mAP=0.5788201160541587
[Epoch 18] Training cost: 4.566, ObjLoss=7.127,BoxCenterLoss=3.513,BoxScaleLoss=0.981,ClassLoss=0.270
[Epoch 18] Validation: motorbike=0.6062388591800356 mAP=0.6062388591800356
[Epoch 19] Training cost: 3.895, ObjLoss=6.654,BoxCenterLoss=3.671,BoxScaleLoss=0.973,ClassLoss=0.331
[Epoch 19] Validation: motorbike=0.6621449867924238 mAP=0.6621449867924238
[Epoch 20] Training cost: 3.794, ObjLoss=7.421,BoxCenterLoss=3.565,BoxScaleLoss=0.942,ClassLoss=0.310
[Epoch 20] Validation: motorbike=0.6307495358897228 mAP=0.6307495358897228
[Epoch 21] Training cost: 6.393, ObjLoss=6.613,BoxCenterLoss=3.574,BoxScaleLoss=0.912,ClassLoss=0.264
[Epoch 21] Validation: motorbike=0.6865800671998838 mAP=0.6865800671998838
[Epoch 22] Training cost: 4.283, ObjLoss=6.023,BoxCenterLoss=3.566,BoxScaleLoss=0.860,ClassLoss=0.282
[Epoch 22] Validation: motorbike=0.675291769041769 mAP=0.675291769041769
[Epoch 23] Training cost: 4.517, ObjLoss=6.309,BoxCenterLoss=3.702,BoxScaleLoss=1.034,ClassLoss=0.310
[Epoch 23] Validation: motorbike=0.6975172176308541 mAP=0.6975172176308541
[Epoch 24] Training cost: 4.813, ObjLoss=6.433,BoxCenterLoss=3.571,BoxScaleLoss=0.875,ClassLoss=0.236
[Epoch 24] Validation: motorbike=0.698904060925919 mAP=0.698904060925919
[Epoch 25] Training cost: 5.283, ObjLoss=6.215,BoxCenterLoss=3.582,BoxScaleLoss=0.873,ClassLoss=0.262
[Epoch 25] Validation: motorbike=0.7323613493424814 mAP=0.7323613493424814
[Epoch 26] Training cost: 4.791, ObjLoss=6.304,BoxCenterLoss=3.771,BoxScaleLoss=0.951,ClassLoss=0.267
[Epoch 26] Validation: motorbike=0.7079858620510422 mAP=0.7079858620510422
[Epoch 27] Training cost: 5.847, ObjLoss=6.318,BoxCenterLoss=3.459,BoxScaleLoss=0.865,ClassLoss=0.183
[Epoch 27] Validation: motorbike=0.6644504791846856 mAP=0.6644504791846856
[Epoch 28] Training cost: 3.551, ObjLoss=6.749,BoxCenterLoss=3.397,BoxScaleLoss=0.937,ClassLoss=0.228
[Epoch 28] Validation: motorbike=0.7024792831428989 mAP=0.7024792831428989
[Epoch 29] Training cost: 3.200, ObjLoss=6.187,BoxCenterLoss=3.511,BoxScaleLoss=0.920,ClassLoss=0.273
[Epoch 29] Validation: motorbike=0.7076846900376312 mAP=0.7076846900376312
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f5763cc5890>, '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.562, ObjLoss=887.102,BoxCenterLoss=4.093,BoxScaleLoss=3.044,ClassLoss=1.044
[Epoch 0] Validation: motorbike=0.037996125496125494 mAP=0.037996125496125494
[Epoch 1] Training cost: 6.496, ObjLoss=16.084,BoxCenterLoss=3.649,BoxScaleLoss=2.169,ClassLoss=0.954
[Epoch 1] Validation: motorbike=0.0606060606060606 mAP=0.0606060606060606
[Epoch 2] Training cost: 4.896, ObjLoss=15.092,BoxCenterLoss=3.750,BoxScaleLoss=2.006,ClassLoss=0.766
[Epoch 2] Validation: motorbike=0.1590909090909091 mAP=0.1590909090909091
[Epoch 3] Training cost: 3.133, ObjLoss=14.690,BoxCenterLoss=3.629,BoxScaleLoss=1.718,ClassLoss=0.727
[Epoch 3] Validation: motorbike=0.36803701349155893 mAP=0.36803701349155893
[Epoch 4] Training cost: 6.781, ObjLoss=8.942,BoxCenterLoss=3.520,BoxScaleLoss=1.424,ClassLoss=0.641
[Epoch 4] Validation: motorbike=0.5534060016302933 mAP=0.5534060016302933
[Epoch 5] Training cost: 7.041, ObjLoss=8.554,BoxCenterLoss=3.824,BoxScaleLoss=1.392,ClassLoss=0.607
[Epoch 5] Validation: motorbike=0.5879761395300503 mAP=0.5879761395300503
[Epoch 6] Training cost: 4.394, ObjLoss=6.684,BoxCenterLoss=3.651,BoxScaleLoss=1.271,ClassLoss=0.627
[Epoch 6] Validation: motorbike=0.4844534595537572 mAP=0.4844534595537572
[Epoch 7] Training cost: 4.264, ObjLoss=6.091,BoxCenterLoss=3.541,BoxScaleLoss=1.207,ClassLoss=0.576
[Epoch 7] Validation: motorbike=0.6402335570730787 mAP=0.6402335570730787
[Epoch 8] Training cost: 5.795, ObjLoss=6.373,BoxCenterLoss=3.614,BoxScaleLoss=1.078,ClassLoss=0.478
[Epoch 8] Validation: motorbike=0.6395235945102967 mAP=0.6395235945102967
[Epoch 9] Training cost: 6.105, ObjLoss=5.811,BoxCenterLoss=3.434,BoxScaleLoss=1.118,ClassLoss=0.468
[Epoch 9] Validation: motorbike=0.5852359723145232 mAP=0.5852359723145232
[Epoch 10] Training cost: 6.603, ObjLoss=6.082,BoxCenterLoss=3.666,BoxScaleLoss=1.106,ClassLoss=0.469
[Epoch 10] Validation: motorbike=0.7008213782477031 mAP=0.7008213782477031
[Epoch 11] Training cost: 7.710, ObjLoss=5.836,BoxCenterLoss=3.446,BoxScaleLoss=0.974,ClassLoss=0.365
[Epoch 11] Validation: motorbike=0.6964027628059248 mAP=0.6964027628059248
[Epoch 12] Training cost: 3.360, ObjLoss=5.822,BoxCenterLoss=3.565,BoxScaleLoss=1.196,ClassLoss=0.489
[Epoch 12] Validation: motorbike=0.5473640670125532 mAP=0.5473640670125532
[Epoch 13] Training cost: 4.336, ObjLoss=5.325,BoxCenterLoss=3.607,BoxScaleLoss=1.127,ClassLoss=0.478
[Epoch 13] Validation: motorbike=0.7417550992104767 mAP=0.7417550992104767
[Epoch 14] Training cost: 4.868, ObjLoss=4.891,BoxCenterLoss=3.552,BoxScaleLoss=0.994,ClassLoss=0.360
[Epoch 14] Validation: motorbike=0.8082019042170845 mAP=0.8082019042170845
[Epoch 15] Training cost: 7.981, ObjLoss=5.846,BoxCenterLoss=3.521,BoxScaleLoss=0.931,ClassLoss=0.343
[Epoch 15] Validation: motorbike=0.7953262353262354 mAP=0.7953262353262354
[Epoch 16] Training cost: 3.355, ObjLoss=5.768,BoxCenterLoss=3.662,BoxScaleLoss=1.072,ClassLoss=0.475
[Epoch 16] Validation: motorbike=0.7889809780673367 mAP=0.7889809780673367
[Epoch 17] Training cost: 7.754, ObjLoss=5.666,BoxCenterLoss=3.620,BoxScaleLoss=0.944,ClassLoss=0.303
[Epoch 17] Validation: motorbike=0.7905991559397744 mAP=0.7905991559397744
[Epoch 18] Training cost: 5.105, ObjLoss=4.884,BoxCenterLoss=3.463,BoxScaleLoss=0.951,ClassLoss=0.336
[Epoch 18] Validation: motorbike=0.7903256547374193 mAP=0.7903256547374193
[Epoch 19] Training cost: 4.215, ObjLoss=4.978,BoxCenterLoss=3.807,BoxScaleLoss=0.994,ClassLoss=0.426
[Epoch 19] Validation: motorbike=0.7903385876091482 mAP=0.7903385876091482
[Epoch 20] Training cost: 4.059, ObjLoss=4.805,BoxCenterLoss=3.577,BoxScaleLoss=0.949,ClassLoss=0.354
[Epoch 20] Validation: motorbike=0.8009072808724378 mAP=0.8009072808724378
[Epoch 21] Training cost: 6.409, ObjLoss=4.827,BoxCenterLoss=3.660,BoxScaleLoss=0.925,ClassLoss=0.321
[Epoch 21] Validation: motorbike=0.8172776400299578 mAP=0.8172776400299578
[Epoch 22] Training cost: 4.397, ObjLoss=4.333,BoxCenterLoss=3.564,BoxScaleLoss=0.885,ClassLoss=0.337
[Epoch 22] Validation: motorbike=0.7754881180155596 mAP=0.7754881180155596
[Epoch 23] Training cost: 4.517, ObjLoss=4.455,BoxCenterLoss=3.519,BoxScaleLoss=0.890,ClassLoss=0.353
[Epoch 23] Validation: motorbike=0.8195049696149405 mAP=0.8195049696149405
[Epoch 24] Training cost: 5.232, ObjLoss=4.634,BoxCenterLoss=3.500,BoxScaleLoss=0.845,ClassLoss=0.269
[Epoch 24] Validation: motorbike=0.8382450882450881 mAP=0.8382450882450881
[Epoch 25] Training cost: 5.381, ObjLoss=4.062,BoxCenterLoss=3.287,BoxScaleLoss=0.836,ClassLoss=0.286
[Epoch 25] Validation: motorbike=0.7738388064591272 mAP=0.7738388064591272
[Epoch 26] Training cost: 4.740, ObjLoss=4.425,BoxCenterLoss=3.571,BoxScaleLoss=0.908,ClassLoss=0.251
[Epoch 26] Validation: motorbike=0.8479450524905072 mAP=0.8479450524905072
[Epoch 27] Training cost: 5.582, ObjLoss=4.237,BoxCenterLoss=3.296,BoxScaleLoss=0.832,ClassLoss=0.233
[Epoch 27] Validation: motorbike=0.8180602131829173 mAP=0.8180602131829173
[Epoch 28] Training cost: 3.891, ObjLoss=4.407,BoxCenterLoss=3.516,BoxScaleLoss=0.882,ClassLoss=0.305
[Epoch 28] Validation: motorbike=0.7625011784847852 mAP=0.7625011784847852
[Epoch 29] Training cost: 3.356, ObjLoss=4.595,BoxCenterLoss=3.462,BoxScaleLoss=0.933,ClassLoss=0.349
[Epoch 29] Validation: motorbike=0.8517134380770746 mAP=0.8517134380770746
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f5762c9d350>, '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.125, ObjLoss=714.070,BoxCenterLoss=3.953,BoxScaleLoss=2.782,ClassLoss=1.066
[Epoch 1] Training cost: 4.993, ObjLoss=16.216,BoxCenterLoss=3.986,BoxScaleLoss=2.079,ClassLoss=0.929
[Epoch 2] Training cost: 6.567, ObjLoss=13.548,BoxCenterLoss=3.808,BoxScaleLoss=1.737,ClassLoss=0.769
[Epoch 3] Training cost: 9.348, ObjLoss=9.394,BoxCenterLoss=3.688,BoxScaleLoss=1.386,ClassLoss=0.639
[Epoch 4] Training cost: 5.197, ObjLoss=7.751,BoxCenterLoss=3.781,BoxScaleLoss=1.417,ClassLoss=0.694
[Epoch 5] Training cost: 7.772, ObjLoss=7.193,BoxCenterLoss=3.709,BoxScaleLoss=1.225,ClassLoss=0.580
[Epoch 6] Training cost: 7.857, ObjLoss=6.230,BoxCenterLoss=3.526,BoxScaleLoss=1.107,ClassLoss=0.455
[Epoch 7] Training cost: 4.567, ObjLoss=6.463,BoxCenterLoss=3.585,BoxScaleLoss=1.129,ClassLoss=0.535
[Epoch 8] Training cost: 7.514, ObjLoss=6.303,BoxCenterLoss=3.678,BoxScaleLoss=1.222,ClassLoss=0.440
[Epoch 9] Training cost: 6.080, ObjLoss=5.188,BoxCenterLoss=3.326,BoxScaleLoss=0.991,ClassLoss=0.352
[Epoch 10] Training cost: 4.913, ObjLoss=5.249,BoxCenterLoss=3.683,BoxScaleLoss=1.051,ClassLoss=0.455
[Epoch 11] Training cost: 6.399, ObjLoss=5.537,BoxCenterLoss=3.641,BoxScaleLoss=0.994,ClassLoss=0.419
[Epoch 12] Training cost: 6.763, ObjLoss=5.164,BoxCenterLoss=3.551,BoxScaleLoss=1.018,ClassLoss=0.384
[Epoch 13] Training cost: 8.651, ObjLoss=5.910,BoxCenterLoss=3.484,BoxScaleLoss=0.880,ClassLoss=0.317
[Epoch 14] Training cost: 6.707, ObjLoss=4.934,BoxCenterLoss=3.534,BoxScaleLoss=1.026,ClassLoss=0.330
[Epoch 15] Training cost: 5.374, ObjLoss=4.615,BoxCenterLoss=3.499,BoxScaleLoss=0.941,ClassLoss=0.333
[Epoch 16] Training cost: 4.090, ObjLoss=5.190,BoxCenterLoss=3.503,BoxScaleLoss=0.996,ClassLoss=0.397
[Epoch 17] Training cost: 4.145, ObjLoss=4.897,BoxCenterLoss=3.555,BoxScaleLoss=0.991,ClassLoss=0.387
[Epoch 18] Training cost: 7.801, ObjLoss=5.490,BoxCenterLoss=3.500,BoxScaleLoss=0.885,ClassLoss=0.263
[Epoch 19] Training cost: 4.098, ObjLoss=4.454,BoxCenterLoss=3.414,BoxScaleLoss=0.944,ClassLoss=0.339
[Epoch 20] Training cost: 5.567, ObjLoss=4.687,BoxCenterLoss=3.448,BoxScaleLoss=0.810,ClassLoss=0.293
[Epoch 21] Training cost: 6.119, ObjLoss=4.344,BoxCenterLoss=3.394,BoxScaleLoss=0.894,ClassLoss=0.240
[Epoch 22] Training cost: 6.198, ObjLoss=4.297,BoxCenterLoss=3.386,BoxScaleLoss=0.848,ClassLoss=0.282
[Epoch 23] Training cost: 5.223, ObjLoss=4.364,BoxCenterLoss=3.521,BoxScaleLoss=0.824,ClassLoss=0.268
[Epoch 24] Training cost: 6.667, ObjLoss=4.581,BoxCenterLoss=3.439,BoxScaleLoss=0.904,ClassLoss=0.216
[Epoch 25] Training cost: 8.033, ObjLoss=4.585,BoxCenterLoss=3.223,BoxScaleLoss=0.767,ClassLoss=0.189
[Epoch 26] Training cost: 6.012, ObjLoss=4.676,BoxCenterLoss=3.597,BoxScaleLoss=0.915,ClassLoss=0.243
[Epoch 27] Training cost: 5.884, ObjLoss=4.047,BoxCenterLoss=3.446,BoxScaleLoss=0.824,ClassLoss=0.231
[Epoch 28] Training cost: 8.345, ObjLoss=4.933,BoxCenterLoss=3.538,BoxScaleLoss=0.935,ClassLoss=0.195
[Epoch 29] Training cost: 4.565, ObjLoss=4.532,BoxCenterLoss=3.548,BoxScaleLoss=1.082,ClassLoss=0.262
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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.8163115392070142

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)