Esempio n. 1
0
def test_add_output_layer():
    model1 = dpp.ClassificationModel()
    model2 = dpp.SemanticSegmentationModel()
    model3 = dpp.CountCeptionModel()
    model1.set_image_dimensions(5, 5, 3)
    model2.set_image_dimensions(5, 5, 3)

    with pytest.raises(RuntimeError):
        model1.add_output_layer(2.5, 3)
    model1.add_input_layer()
    model2.add_input_layer()
    model3.add_input_layer()
    with pytest.raises(TypeError):
        model1.add_output_layer("2")
    with pytest.raises(ValueError):
        model1.add_output_layer(-0.4)
    with pytest.raises(TypeError):
        model1.add_output_layer(2.0, 3.4)
    with pytest.raises(ValueError):
        model1.add_output_layer(2.0, -4)
    with pytest.raises(RuntimeError):
        model2.add_output_layer(
            output_size=3
        )  # Semantic segmentation needed for this runtime error to occur

    model1.add_output_layer(2.5, 3)
    assert isinstance(model1._last_layer(), dpp.layers.fullyConnectedLayer)
    with pytest.warns(Warning):
        model2.add_output_layer(regularization_coefficient=2.0)
    assert isinstance(model2._last_layer(), dpp.layers.convLayer)
    model3.add_output_layer()
    assert isinstance(model3._last_layer(), dpp.layers.inputLayer)
#
# Demonstrates training a general-purpose image classifier on the popular CIFAR10 image classification dataset.
# Assumes that you downloaded CIFAR10 image files via nvidia DIGITS.
#

import deepplantphenomics as dpp

model = dpp.ClassificationModel(debug=True, load_from_saved=False)

# 3 channels for colour, 1 channel for greyscale
channels = 3

# Setup and hyper-parameters
model.set_image_dimensions(32, 32, channels)

model.set_regularization_coefficient(0.004)
model.set_batch_size(32)
model.set_learning_rate(0.0001)
model.set_maximum_training_epochs(25)

# Augmentation options
model.set_augmentation_flip_horizontal(True)
model.set_augmentation_crop(True)
model.set_augmentation_brightness_and_contrast(True)

# Load dataset
model.load_cifar10_dataset_from_directory('./data/cifar10')

# Use a VGG-16 network
model.use_predefined_model('vgg-16')
Esempio n. 3
0

def test_set_patch_size(model):
    with pytest.raises(TypeError):
        model.set_patch_size(1.0, 1)
    with pytest.raises(ValueError):
        model.set_patch_size(-1, 1)
    with pytest.raises(TypeError):
        model.set_patch_size(1, 1.0)
    with pytest.raises(ValueError):
        model.set_patch_size(1, -1)


@pytest.mark.parametrize(
    "model,bad_loss,good_loss",
    [(dpp.ClassificationModel(), 'l2', 'softmax cross entropy'),
     (dpp.RegressionModel(), 'softmax cross entropy', 'l2'),
     (dpp.SemanticSegmentationModel(), 'l2', 'sigmoid cross entropy'),
     (dpp.ObjectDetectionModel(), 'l2', 'yolo'),
     (dpp.CountCeptionModel(), 'l2', 'l1'),
     (dpp.HeatmapObjectCountingModel(), 'l1', 'sigmoid cross entropy')])
def test_set_loss_function(model, bad_loss, good_loss):
    with pytest.raises(TypeError):
        model.set_loss_function(0)
    with pytest.raises(ValueError):
        model.set_loss_function(bad_loss)
    model.set_loss_function(good_loss)


def test_set_yolo_parameters():
    model = dpp.ObjectDetectionModel()