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, 30553.64KB/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/21814/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 0x7f65b0334150>, '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.540, ObjLoss=1728.677,BoxCenterLoss=3.354,BoxScaleLoss=2.234,ClassLoss=0.902
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 5.906, ObjLoss=56.102,BoxCenterLoss=3.515,BoxScaleLoss=1.440,ClassLoss=0.817
[Epoch 1] Validation: motorbike=0.0 mAP=0.0
[Epoch 2] Training cost: 4.639, ObjLoss=61.494,BoxCenterLoss=3.626,BoxScaleLoss=1.389,ClassLoss=0.812
[Epoch 2] Validation: motorbike=0.01515151515151515 mAP=0.01515151515151515
[Epoch 3] Training cost: 5.016, ObjLoss=79.056,BoxCenterLoss=3.294,BoxScaleLoss=1.130,ClassLoss=0.704
[Epoch 3] Validation: motorbike=0.05705996131528046 mAP=0.05705996131528046
[Epoch 4] Training cost: 3.559, ObjLoss=82.507,BoxCenterLoss=3.376,BoxScaleLoss=1.366,ClassLoss=0.677
[Epoch 4] Validation: motorbike=0.0 mAP=0.0
[Epoch 5] Training cost: 4.844, ObjLoss=106.664,BoxCenterLoss=3.599,BoxScaleLoss=1.289,ClassLoss=0.692
[Epoch 5] Validation: motorbike=0.0 mAP=0.0
[Epoch 6] Training cost: 3.146, ObjLoss=116.688,BoxCenterLoss=3.362,BoxScaleLoss=1.097,ClassLoss=0.631
[Epoch 6] Validation: motorbike=0.0677873528340818 mAP=0.0677873528340818
[Epoch 7] Training cost: 6.809, ObjLoss=82.792,BoxCenterLoss=3.530,BoxScaleLoss=1.344,ClassLoss=0.609
[Epoch 7] Validation: motorbike=0.016940278972364536 mAP=0.016940278972364536
[Epoch 8] Training cost: 5.528, ObjLoss=61.695,BoxCenterLoss=3.612,BoxScaleLoss=1.171,ClassLoss=0.570
[Epoch 8] Validation: motorbike=0.0031422468608398257 mAP=0.0031422468608398257
[Epoch 9] Training cost: 3.029, ObjLoss=75.446,BoxCenterLoss=3.614,BoxScaleLoss=1.150,ClassLoss=0.617
[Epoch 9] Validation: motorbike=0.076303160204089 mAP=0.076303160204089
[Epoch 10] Training cost: 4.952, ObjLoss=62.836,BoxCenterLoss=3.673,BoxScaleLoss=1.381,ClassLoss=0.544
[Epoch 10] Validation: motorbike=0.012987012987012986 mAP=0.012987012987012986
[Epoch 11] Training cost: 3.578, ObjLoss=50.675,BoxCenterLoss=3.612,BoxScaleLoss=1.142,ClassLoss=0.565
[Epoch 11] Validation: motorbike=0.13601609989413493 mAP=0.13601609989413493
[Epoch 12] Training cost: 3.358, ObjLoss=46.010,BoxCenterLoss=3.577,BoxScaleLoss=1.063,ClassLoss=0.548
[Epoch 12] Validation: motorbike=0.11688311688311688 mAP=0.11688311688311688
[Epoch 13] Training cost: 3.087, ObjLoss=25.587,BoxCenterLoss=3.360,BoxScaleLoss=1.037,ClassLoss=0.497
[Epoch 13] Validation: motorbike=0.17164502164502166 mAP=0.17164502164502166
[Epoch 14] Training cost: 4.910, ObjLoss=150.193,BoxCenterLoss=3.436,BoxScaleLoss=1.229,ClassLoss=0.444
[Epoch 14] Validation: motorbike=0.0 mAP=0.0
[Epoch 15] Training cost: 3.261, ObjLoss=450.205,BoxCenterLoss=3.742,BoxScaleLoss=1.692,ClassLoss=0.523
[Epoch 15] Validation: motorbike=0.0 mAP=0.0
[Epoch 16] Training cost: 3.804, ObjLoss=335.693,BoxCenterLoss=3.623,BoxScaleLoss=1.688,ClassLoss=0.520
[Epoch 16] Validation: motorbike=0.0 mAP=0.0
[Epoch 17] Training cost: 4.271, ObjLoss=409.696,BoxCenterLoss=3.582,BoxScaleLoss=1.834,ClassLoss=0.480
[Epoch 17] Validation: motorbike=0.0 mAP=0.0
[Epoch 18] Training cost: 2.967, ObjLoss=417.490,BoxCenterLoss=3.564,BoxScaleLoss=1.964,ClassLoss=0.497
[Epoch 18] Validation: motorbike=0.0 mAP=0.0
[Epoch 19] Training cost: 5.215, ObjLoss=260.647,BoxCenterLoss=3.529,BoxScaleLoss=1.566,ClassLoss=0.550
[Epoch 19] Validation: motorbike=0.0 mAP=0.0
[Epoch 20] Training cost: 2.854, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 20] Validation: motorbike=0.0 mAP=0.0
[Epoch 21] Training cost: 4.562, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 21] Validation: motorbike=0.0 mAP=0.0
[Epoch 22] Training cost: 5.268, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 22] Validation: motorbike=0.0 mAP=0.0
[Epoch 23] Training cost: 3.977, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 23] Validation: motorbike=0.0 mAP=0.0
[Epoch 24] Training cost: 4.411, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 24] Validation: motorbike=0.0 mAP=0.0
[Epoch 25] Training cost: 3.652, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 25] Validation: motorbike=0.0 mAP=0.0
[Epoch 26] Training cost: 3.908, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 26] Validation: motorbike=0.0 mAP=0.0
[Epoch 27] Training cost: 5.844, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 27] Validation: motorbike=0.0 mAP=0.0
[Epoch 28] Training cost: 3.786, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 28] Validation: motorbike=0.0 mAP=0.0
[Epoch 29] Training cost: 4.815, ObjLoss=nan,BoxCenterLoss=nan,BoxScaleLoss=nan,ClassLoss=nan
[Epoch 29] Validation: motorbike=0.0 mAP=0.0
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f65b033dc10>, '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.844, ObjLoss=1828.451,BoxCenterLoss=3.813,BoxScaleLoss=3.056,ClassLoss=1.095
[Epoch 0] Validation: motorbike=0.0 mAP=0.0
[Epoch 1] Training cost: 6.016, ObjLoss=20.644,BoxCenterLoss=3.660,BoxScaleLoss=2.021,ClassLoss=0.908
[Epoch 1] Validation: motorbike=0.0 mAP=0.0
[Epoch 2] Training cost: 4.821, ObjLoss=22.865,BoxCenterLoss=3.828,BoxScaleLoss=1.710,ClassLoss=0.787
[Epoch 2] Validation: motorbike=0.09090909090909091 mAP=0.09090909090909091
[Epoch 3] Training cost: 4.280, ObjLoss=15.192,BoxCenterLoss=3.525,BoxScaleLoss=1.456,ClassLoss=0.725
[Epoch 3] Validation: motorbike=0.26468769325912184 mAP=0.26468769325912184
[Epoch 4] Training cost: 3.923, ObjLoss=9.464,BoxCenterLoss=3.550,BoxScaleLoss=1.250,ClassLoss=0.719
[Epoch 4] Validation: motorbike=0.25095924388993185 mAP=0.25095924388993185
[Epoch 5] Training cost: 5.173, ObjLoss=7.237,BoxCenterLoss=3.609,BoxScaleLoss=1.216,ClassLoss=0.707
[Epoch 5] Validation: motorbike=0.4045810408912117 mAP=0.4045810408912117
[Epoch 6] Training cost: 3.308, ObjLoss=7.728,BoxCenterLoss=3.529,BoxScaleLoss=1.240,ClassLoss=0.677
[Epoch 6] Validation: motorbike=0.4352582006513524 mAP=0.4352582006513524
[Epoch 7] Training cost: 7.303, ObjLoss=6.741,BoxCenterLoss=3.473,BoxScaleLoss=0.997,ClassLoss=0.542
[Epoch 7] Validation: motorbike=0.3621498362760816 mAP=0.3621498362760816
[Epoch 8] Training cost: 5.849, ObjLoss=7.218,BoxCenterLoss=3.493,BoxScaleLoss=0.931,ClassLoss=0.530
[Epoch 8] Validation: motorbike=0.45813437534529894 mAP=0.45813437534529894
[Epoch 9] Training cost: 3.300, ObjLoss=6.981,BoxCenterLoss=3.645,BoxScaleLoss=1.004,ClassLoss=0.620
[Epoch 9] Validation: motorbike=0.6355245779365954 mAP=0.6355245779365954
[Epoch 10] Training cost: 5.089, ObjLoss=5.851,BoxCenterLoss=3.491,BoxScaleLoss=1.012,ClassLoss=0.531
[Epoch 10] Validation: motorbike=0.6799429365059435 mAP=0.6799429365059435
[Epoch 11] Training cost: 3.911, ObjLoss=6.304,BoxCenterLoss=3.545,BoxScaleLoss=0.970,ClassLoss=0.537
[Epoch 11] Validation: motorbike=0.7315506569610486 mAP=0.7315506569610486
[Epoch 12] Training cost: 3.476, ObjLoss=5.708,BoxCenterLoss=3.349,BoxScaleLoss=0.981,ClassLoss=0.493
[Epoch 12] Validation: motorbike=0.7309144639539389 mAP=0.7309144639539389
[Epoch 13] Training cost: 3.325, ObjLoss=5.846,BoxCenterLoss=3.592,BoxScaleLoss=1.080,ClassLoss=0.536
[Epoch 13] Validation: motorbike=0.7311828198391016 mAP=0.7311828198391016
[Epoch 14] Training cost: 5.007, ObjLoss=5.240,BoxCenterLoss=3.437,BoxScaleLoss=0.865,ClassLoss=0.410
[Epoch 14] Validation: motorbike=0.690794885447292 mAP=0.690794885447292
[Epoch 15] Training cost: 3.308, ObjLoss=5.429,BoxCenterLoss=3.589,BoxScaleLoss=1.112,ClassLoss=0.495
[Epoch 15] Validation: motorbike=0.7452036999708839 mAP=0.7452036999708839
[Epoch 16] Training cost: 4.012, ObjLoss=4.780,BoxCenterLoss=3.322,BoxScaleLoss=0.876,ClassLoss=0.406
[Epoch 16] Validation: motorbike=0.7464868954332636 mAP=0.7464868954332636
[Epoch 17] Training cost: 4.357, ObjLoss=5.208,BoxCenterLoss=3.400,BoxScaleLoss=0.880,ClassLoss=0.400
[Epoch 17] Validation: motorbike=0.7777535543523004 mAP=0.7777535543523004
[Epoch 18] Training cost: 3.092, ObjLoss=5.071,BoxCenterLoss=3.475,BoxScaleLoss=0.860,ClassLoss=0.440
[Epoch 18] Validation: motorbike=0.7969996669996671 mAP=0.7969996669996671
[Epoch 19] Training cost: 5.491, ObjLoss=5.232,BoxCenterLoss=3.703,BoxScaleLoss=0.915,ClassLoss=0.383
[Epoch 19] Validation: motorbike=0.8080568113720668 mAP=0.8080568113720668
[Epoch 20] Training cost: 3.002, ObjLoss=5.145,BoxCenterLoss=3.441,BoxScaleLoss=0.977,ClassLoss=0.450
[Epoch 20] Validation: motorbike=0.8033157885029375 mAP=0.8033157885029375
[Epoch 21] Training cost: 4.988, ObjLoss=4.518,BoxCenterLoss=3.269,BoxScaleLoss=0.839,ClassLoss=0.321
[Epoch 21] Validation: motorbike=0.7726702090930433 mAP=0.7726702090930433
[Epoch 22] Training cost: 5.795, ObjLoss=5.295,BoxCenterLoss=3.511,BoxScaleLoss=0.839,ClassLoss=0.348
[Epoch 22] Validation: motorbike=0.7819407753618279 mAP=0.7819407753618279
[Epoch 23] Training cost: 4.565, ObjLoss=4.342,BoxCenterLoss=3.362,BoxScaleLoss=0.772,ClassLoss=0.297
[Epoch 23] Validation: motorbike=0.8447277654594728 mAP=0.8447277654594728
[Epoch 24] Training cost: 4.816, ObjLoss=4.377,BoxCenterLoss=3.409,BoxScaleLoss=0.788,ClassLoss=0.305
[Epoch 24] Validation: motorbike=0.8055123753021628 mAP=0.8055123753021628
[Epoch 25] Training cost: 4.127, ObjLoss=4.168,BoxCenterLoss=3.467,BoxScaleLoss=0.799,ClassLoss=0.311
[Epoch 25] Validation: motorbike=0.8432385568407441 mAP=0.8432385568407441
[Epoch 26] Training cost: 4.431, ObjLoss=3.938,BoxCenterLoss=3.252,BoxScaleLoss=0.766,ClassLoss=0.274
[Epoch 26] Validation: motorbike=0.7696808475681383 mAP=0.7696808475681383
[Epoch 27] Training cost: 6.233, ObjLoss=4.595,BoxCenterLoss=3.438,BoxScaleLoss=0.831,ClassLoss=0.268
[Epoch 27] Validation: motorbike=0.8221063650731747 mAP=0.8221063650731747
[Epoch 28] Training cost: 4.111, ObjLoss=4.206,BoxCenterLoss=3.345,BoxScaleLoss=0.778,ClassLoss=0.276
[Epoch 28] Validation: motorbike=0.8156504430386627 mAP=0.8156504430386627
[Epoch 29] Training cost: 5.412, ObjLoss=4.220,BoxCenterLoss=3.239,BoxScaleLoss=0.734,ClassLoss=0.245
[Epoch 29] Validation: motorbike=0.8067541739478498 mAP=0.8067541739478498
{'meta_arch': 'yolo3', 'dataset': <autogluon.task.object_detection.dataset.voc.CustomVOCDetection object at 0x7f64daddcd10>, '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.636, ObjLoss=712.717,BoxCenterLoss=3.779,BoxScaleLoss=2.847,ClassLoss=1.013
[Epoch 1] Training cost: 4.767, ObjLoss=14.934,BoxCenterLoss=3.679,BoxScaleLoss=2.011,ClassLoss=0.895
[Epoch 2] Training cost: 6.046, ObjLoss=14.090,BoxCenterLoss=3.711,BoxScaleLoss=1.620,ClassLoss=0.780
[Epoch 3] Training cost: 8.902, ObjLoss=10.394,BoxCenterLoss=3.549,BoxScaleLoss=1.375,ClassLoss=0.633
[Epoch 4] Training cost: 4.809, ObjLoss=8.213,BoxCenterLoss=3.829,BoxScaleLoss=1.479,ClassLoss=0.671
[Epoch 5] Training cost: 7.190, ObjLoss=7.346,BoxCenterLoss=3.767,BoxScaleLoss=1.184,ClassLoss=0.567
[Epoch 6] Training cost: 7.465, ObjLoss=6.686,BoxCenterLoss=3.608,BoxScaleLoss=1.127,ClassLoss=0.492
[Epoch 7] Training cost: 4.440, ObjLoss=6.070,BoxCenterLoss=3.533,BoxScaleLoss=1.163,ClassLoss=0.547
[Epoch 8] Training cost: 7.227, ObjLoss=6.060,BoxCenterLoss=3.667,BoxScaleLoss=0.977,ClassLoss=0.428
[Epoch 9] Training cost: 6.137, ObjLoss=5.701,BoxCenterLoss=3.511,BoxScaleLoss=1.049,ClassLoss=0.417
[Epoch 10] Training cost: 4.511, ObjLoss=5.219,BoxCenterLoss=3.478,BoxScaleLoss=0.944,ClassLoss=0.406
[Epoch 11] Training cost: 5.721, ObjLoss=5.600,BoxCenterLoss=3.595,BoxScaleLoss=1.040,ClassLoss=0.406
[Epoch 12] Training cost: 5.881, ObjLoss=5.343,BoxCenterLoss=3.586,BoxScaleLoss=1.024,ClassLoss=0.380
[Epoch 13] Training cost: 8.200, ObjLoss=5.429,BoxCenterLoss=3.406,BoxScaleLoss=0.880,ClassLoss=0.281
[Epoch 14] Training cost: 6.389, ObjLoss=5.093,BoxCenterLoss=3.489,BoxScaleLoss=1.019,ClassLoss=0.329
[Epoch 15] Training cost: 4.836, ObjLoss=4.602,BoxCenterLoss=3.347,BoxScaleLoss=0.903,ClassLoss=0.308
[Epoch 16] Training cost: 3.917, ObjLoss=5.369,BoxCenterLoss=3.666,BoxScaleLoss=1.088,ClassLoss=0.396
[Epoch 17] Training cost: 3.670, ObjLoss=5.024,BoxCenterLoss=3.438,BoxScaleLoss=0.948,ClassLoss=0.360
[Epoch 18] Training cost: 7.437, ObjLoss=5.300,BoxCenterLoss=3.589,BoxScaleLoss=0.974,ClassLoss=0.258
[Epoch 19] Training cost: 3.817, ObjLoss=4.833,BoxCenterLoss=3.570,BoxScaleLoss=1.015,ClassLoss=0.360
[Epoch 20] Training cost: 5.280, ObjLoss=4.832,BoxCenterLoss=3.590,BoxScaleLoss=1.025,ClassLoss=0.324
[Epoch 21] Training cost: 5.604, ObjLoss=4.985,BoxCenterLoss=3.585,BoxScaleLoss=0.987,ClassLoss=0.292
[Epoch 22] Training cost: 5.291, ObjLoss=4.731,BoxCenterLoss=3.573,BoxScaleLoss=1.017,ClassLoss=0.297
[Epoch 23] Training cost: 5.311, ObjLoss=4.436,BoxCenterLoss=3.517,BoxScaleLoss=0.929,ClassLoss=0.281
[Epoch 24] Training cost: 5.981, ObjLoss=4.573,BoxCenterLoss=3.491,BoxScaleLoss=0.843,ClassLoss=0.228
[Epoch 25] Training cost: 7.674, ObjLoss=4.671,BoxCenterLoss=3.428,BoxScaleLoss=0.863,ClassLoss=0.217
[Epoch 26] Training cost: 5.345, ObjLoss=4.378,BoxCenterLoss=3.562,BoxScaleLoss=0.882,ClassLoss=0.232
[Epoch 27] Training cost: 6.061, ObjLoss=4.136,BoxCenterLoss=3.414,BoxScaleLoss=0.942,ClassLoss=0.217
[Epoch 28] Training cost: 8.085, ObjLoss=4.932,BoxCenterLoss=3.559,BoxScaleLoss=0.941,ClassLoss=0.200
[Epoch 29] Training cost: 4.236, ObjLoss=4.399,BoxCenterLoss=3.464,BoxScaleLoss=0.955,ClassLoss=0.254
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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.7788600585360101

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)