Beispiel #1
0
def test_set_density_map_sigma():
    model = dpp.HeatmapObjectCountingModel()
    assert model._density_sigma == 5

    with pytest.raises(TypeError):
        model.set_density_map_sigma('4')
    model.set_density_map_sigma(2.0)
    assert model._density_sigma == 2.0
Beispiel #2
0
def test_heatmap_csv_data_load(test_data_dir):
    im_dir = os.path.join(test_data_dir, 'test_Ara2013_heatmap')
    expected_heatmap_dir = os.path.join(os.path.curdir, 'generated_heatmaps')
    if os.path.exists(expected_heatmap_dir):
        shutil.rmtree(expected_heatmap_dir)

    model = dpp.HeatmapObjectCountingModel()
    model.set_image_dimensions(128, 128, 3)
    assert model._raw_image_files is None
    assert model._raw_labels is None

    base_names = [
        'ara2013_plant007_rgb', 'ara2013_plant008_rgb', 'ara2013_plant001_rgb',
        'ara2013_plant002_rgb', 'ara2013_plant003_rgb', 'ara2013_plant004_rgb',
        'ara2013_plant005_rgb', 'ara2013_plant006_rgb'
    ]
    expected_images = [
        os.path.join(im_dir, '{}.png'.format(x)) for x in base_names
    ]
    expected_labels = [
        os.path.join(expected_heatmap_dir, '{}.npy'.format(x))
        for x in base_names
    ]

    # Load data from CSV; generate heatmaps
    model.load_heatmap_dataset_with_csv_from_directory(im_dir,
                                                       'point_labels.csv',
                                                       ext='png')
    assert model._raw_image_files == expected_images
    assert model._raw_labels == expected_labels

    # Load data from CSV and pre-existing heatmaps
    model._raw_image_files = None
    model._raw_labels = None
    model.load_heatmap_dataset_with_csv_from_directory(im_dir,
                                                       'point_labels.csv',
                                                       ext='png')
    assert model._raw_image_files == expected_images
    assert model._raw_labels == expected_labels

    shutil.rmtree(expected_heatmap_dir)
Beispiel #3
0
import deepplantphenomics as dpp

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

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

# Setup and hyper-parameters
model.set_image_dimensions(128, 128, channels)
model.set_batch_size(32)
model.set_number_of_threads(4)

model.set_learning_rate(0.0001)
model.set_maximum_training_epochs(25)
model.set_test_split(0.75)
model.set_validation_split(0.0)

# Load dataset
model.set_density_map_sigma(4.0)
model.load_heatmap_dataset_with_csv_from_directory('./data', 'point_labels.csv')

# Define a model architecture
model.add_input_layer()

model.add_convolutional_layer(filter_dimension=[3, 3, 3, 16], stride_length=1, activation_function='relu')
model.add_convolutional_layer(filter_dimension=[3, 3, 16, 32], stride_length=1, activation_function='relu')
model.add_convolutional_layer(filter_dimension=[5, 5, 32, 32], stride_length=1, activation_function='relu')

model.add_output_layer()

# Train!
Beispiel #4
0
    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()
    with pytest.raises(RuntimeError):
        model.set_yolo_parameters()
    model.set_image_dimensions(448, 448, 3)
    model.set_yolo_parameters()