Ejemplo n.º 1
0
 def __init__(self, model_dir, batch_size=2):
     """A network which predicts rosette leaf count via a convolutional neural net"""
     
     self.__dir_name = os.path.join(model_dir)
     self.model = dpp.DPPModel(debug=False, load_from_saved=self.__dir_name)
     # Define model hyperparameters
     self.model.set_batch_size(batch_size)
     self.model.set_number_of_threads(1)
     self.model.set_image_dimensions(self.img_height, self.img_width, 3)
     self.model.set_resize_images(True)
     self.model.set_problem_type('regression')
     self.model.set_augmentation_crop(True)
     # Define a model architecture
     self.model.add_input_layer()
     self.model.add_convolutional_layer(filter_dimension=[5, 5, 3, 32], stride_length=1, activation_function='tanh')
     self.model.add_pooling_layer(kernel_size=3, stride_length=2)
     self.model.add_convolutional_layer(filter_dimension=[5, 5, 32, 64], stride_length=1, activation_function='tanh')
     self.model.add_pooling_layer(kernel_size=3, stride_length=2)
     self.model.add_convolutional_layer(filter_dimension=[3, 3, 64, 64], stride_length=1, activation_function='tanh')
     self.model.add_pooling_layer(kernel_size=3, stride_length=2)
     self.model.add_convolutional_layer(filter_dimension=[3, 3, 64, 64], stride_length=1, activation_function='tanh')
     self.model.add_pooling_layer(kernel_size=3, stride_length=2)
     self.model.add_output_layer()
Ejemplo n.º 2
0
#
# An example of training a model for the Days After Germination (DAG) task from the IPPN dataset.
#

import deepplantphenomics as dpp

model = dpp.DPPModel(debug=True, save_checkpoints=False, report_rate=20)

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

# Setup and hyperparameters
model.set_batch_size(16)
model.set_number_of_threads(8)
model.set_image_dimensions(128, 128, channels)
model.set_resize_images(True)

model.set_problem_type('regression')
model.set_num_regression_outputs(1)
model.set_train_test_split(0.8)
model.set_regularization_coefficient(0.001)
model.set_learning_rate(0.0001)
model.set_weight_initializer('normal')
model.set_maximum_training_epochs(1000)

# Augmentation options
model.set_augmentation_brightness_and_contrast(True)
model.set_augmentation_flip_horizontal(True)
model.set_augmentation_flip_vertical(True)
model.set_augmentation_crop(True, crop_ratio=0.8)
Ejemplo n.º 3
0
def train(train_dir, label_fn, model_name, tsrbrd_dir, epoch, split_ratio, lr):
    """
    train_dir: the directory where your training images located
    label_fn: the file name of labels under train_dir. Just specify the file name don't inclde the path. 
    model_name: the name of you model. Model results will be save to the dir in this name
    tsrbrd_dir: dir to save the tensorboard results.
    epoch: specify the epoch. Based on dpp document suggest 100 for plant stress and 500 for counting.
    split_ratio: the ration of validation images and testing images
    lr: specify learnning rate.
    """

    img_dir = Path(train_dir)
    model = dpp.DPPModel(debug=True,
                         save_checkpoints=True,
                         report_rate=150,
                         tensorboard_dir=tsrbrd_dir,
                         save_dir=model_name)
    model.set_batch_size(30)
    model.set_number_of_threads(10)
    model.set_image_dimensions(256, 256, 3)
    model.set_test_split(float(split_ratio))
    model.set_validation_split(float(split_ratio))
    model.set_learning_rate(float(lr))
    model.set_weight_initializer('normal')
    #model.set_weight_initializer('xavier')
    model.set_maximum_training_epochs(int(epoch))

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

    # ALTERNATIVELY - Load labels and images
    model.load_multiple_labels_from_csv(img_dir / label_fn, id_column=0)
    model.load_images_with_ids_from_directory(img_dir)
    #model.load_dataset_from_directory_with_auto_labels(train_dir)

    # Define a model architecture
    model.add_input_layer()
    model.add_convolutional_layer(filter_dimension=[5, 5, 3, 32],
                                  stride_length=1,
                                  activation_function='relu',
                                  regularization_coefficient=0.0)
    model.add_pooling_layer(kernel_size=3, stride_length=2)

    model.add_convolutional_layer(filter_dimension=[5, 5, 32, 32],
                                  stride_length=1,
                                  activation_function='relu',
                                  regularization_coefficient=0.0)
    model.add_pooling_layer(kernel_size=3, stride_length=2)

    model.add_convolutional_layer(filter_dimension=[5, 5, 32, 64],
                                  stride_length=1,
                                  activation_function='relu',
                                  regularization_coefficient=0.0)
    model.add_pooling_layer(kernel_size=3, stride_length=2)

    model.add_fully_connected_layer(output_size=256,
                                    activation_function='relu')
    model.add_output_layer(regularization_coefficient=0.0)

    # Begin training the model
    model.begin_training()
Ejemplo n.º 4
0
#
# This example shows a model which uses the auto-segmentation pre-processor.
# The model is never defined, so running this file only demonstrates auto-segmentation.
#

import deepplantphenomics as dpp

model = dpp.DPPModel(debug=True, load_from_saved=False, initialize=False)

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

# Setup and hyperparameters
model.set_number_of_threads(12)
model.set_image_dimensions(2056, 2454, channels)

# Add auto-segment preprocessor
model.add_preprocessor('auto-segmentation')

# Load all VIS images from a Lemnatec image repository
model.load_lemnatec_images_from_directory('./data')

Ejemplo n.º 5
0
#
# 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.DPPModel(debug=True, load_from_saved=False)

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

# Setup and hyperparameters
model.set_batch_size(128)
model.set_number_of_threads(4)
model.set_image_dimensions(32, 32, channels)

model.set_regularization_coefficient(0.004)
model.set_learning_rate(0.001)
model.set_weight_initializer('normal')
model.set_maximum_training_epochs(700)

# 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')

# Simple CIFAR-10 model