コード例 #1
0
def test_time_out_image_classification():
    time_limit = 30
    from gluoncv.auto.tasks import ImageClassification
    task = ImageClassification({'num_trials': 1, 'epochs': 50})

    tic = time.time()
    classifier = task.fit(IMAGE_CLASS_DATASET, time_limit=time_limit)
    # check time_limit with a little bit overhead
    assert (time.time() - tic) < time_limit + 180
コード例 #2
0
def test_torch_image_classification_custom_net():
    from gluoncv.auto.tasks import ImageClassification
    from timm import create_model
    import torch.nn as nn
    net = create_model('resnet18')
    net.fc = nn.Linear(512, 4)
    task = ImageClassification({'num_trials': 1, 'epochs': 1, 'custom_net': net, 'batch_size': 8})
    classifier = task.fit(IMAGE_CLASS_DATASET)
    assert task.fit_summary().get('valid_acc', 0) > 0
    test_result = classifier.predict(IMAGE_CLASS_TEST)
コード例 #3
0
ファイル: test_auto_tasks.py プロジェクト: yinweisu/gluon-cv
def test_image_classification():
    from gluoncv.auto.tasks import ImageClassification
    task = ImageClassification({
        'model': 'resnet18_v1',
        'num_trials': 1,
        'epochs': 1,
        'batch_size': 8
    })
    classifier = task.fit(IMAGE_CLASS_DATASET)
    assert task.fit_summary().get('valid_acc', 0) > 0
    test_result = classifier.predict(IMAGE_CLASS_TEST)
コード例 #4
0
def test_image_classification_custom_net():
    from gluoncv.auto.tasks import ImageClassification
    from gluoncv.model_zoo import get_model
    net = get_model('resnet18_v1')
    task = ImageClassification({
        'num_trials': 1,
        'epochs': 1,
        'custom_net': net
    })
    classifier = task.fit(IMAGE_CLASS_DATASET)
    assert task.fit_summary().get('valid_acc', 0) > 0
    test_result = classifier.predict(IMAGE_CLASS_TEST)
コード例 #5
0
def test_image_classification():
    from gluoncv.auto.tasks import ImageClassification
    task = ImageClassification({'num_trials': 1})
    classifier = task.fit(IMAGE_CLASS_DATASET)
    assert task.fit_summary.get('valid_acc', 0) > 0
    test_result = classifier.predict(IMAGE_CLASS_TEST)
コード例 #6
0
        'batch_size':
        ag.Int(4, 7),  # [16, 32, 64, 128]
        'momentum':
        ag.Real(0.85, 0.95),
        'wd':
        ag.Real(1e-6, 1e-2, log=True),
        'epochs':
        15,
        'num_trials':
        args.num_trials,
        'search_strategy':
        'bayesopt'
    }

    # specify learning task
    task = ImageClassification(config)

    # specify dataset
    dataset = Dataset.get(args.dataset)
    train_data, valid_data = dataset.split(0.8)

    # fit auto estimator
    classifier = task.fit(train_data, valid_data)

    # evaluate auto estimator
    top1, top5 = classifier.evaluate(valid_data)
    logging.info('evaluation: top1={}, top5={}'.format(top1, top5))

    # save and load auto estimator
    classifier.save('classifier.pkl')
    classifier = ImageClassification.load('classifier.pkl')