def __init__(self, dropout=0.4, input_shape=(229, 229, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct an Inception V3 convolutional neural network dropout : percentage of dropout rate input_shape : the input to the model n_classes : number of output classes include_top : whether to include the classifier initializer : kernel initiaklizer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # The input tensor (299x299 in V3 vs 224x224 in V1/V2) inputs = Input(shape=input_shape) # The stem convolutional group x = self.stem(inputs) # The learner outputs, aux = self.learner(x, n_classes) # The classifier if include_top: outputs = self.classifier(outputs, n_classes, dropout) # Instantiate the Model self._model = Model(inputs, [outputs] + aux)
def __init__(self, input_shape=(32, 32, 3), include_top=True, f1 = 9, f2=1, f3=5, **hyperparameters): """ Construct a Wids Residual (Convolutional Neural) Network f1, f2, f3 : number of filters for convolutional layers n1, n2 and n3 input_shape : input shape include_top : include the reconstruction component initializer : kernel initialization regularizer : kernel regularization relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether use bias in conjunction with batch norm """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # The input tensor inputs = Input(input_shape) # The stem convolutional group x = self.stem(inputs, f1) # The encoder outputs = self.encoder(x, f2) # The reconstruction if include_top: outputs = self.reconstruction(outputs, f3) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, layers=None, input_shape=(32, 32, 3), **hyperparameters): ''' Construct an AutoEncoder input_shape : input shape to the autoencoder layers : the number of filters per layer initializer : kernel initializer regularizer : kernel regularizer relu_clip : clip value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias ''' # Configure base (super) class Composable.__init__(self, input_shape, None, self.hyperparameters, **hyperparameters) if layers is None: layers = self.layers # remember the layers self.layers = layers # remember the input shape self.input_shape = input_shape inputs = Input(input_shape) encoder = self.encoder(inputs, layers=layers) outputs = self.decoder(encoder, layers=layers) self._model = Model(inputs, outputs)
def __init__(self, groups=None , input_shape=(32, 32, 3), include_top=True, **hyperparameters): """ Construct a Wids Residual (Convolutional Neural) Network groups : metaparameter for group configuration input_shape : input shape include_top : include the reconstruction component initializer : kernel initialization regularizer : kernel regularization relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether use bias in conjunction with batch norm """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) if groups is None: groups = self.groups # The input tensor inputs = Input(input_shape) # The stem convolutional group x = self.stem(inputs) # The learner outputs = self.learner(x, groups) # The reconstruction if include_top: outputs = self.decoder(outputs) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, groups=None, dropout=0.5, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): ''' Construct a SqueezeNet Complex Bypass Convolution Neural Network groups : number of blocks/filters per group dropout : percent of dropoput input_shape : input shape to model n_classes : number of output classes include_top : whether to include classifier init_weights: kernel initializer reg : kernel regularizer relu : max value for ReLU bias : whether to use bias in conjunction with batch norm ''' Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) if groups is None: groups = list(SqueezeNetComplex.groups) # The input shape inputs = Input(shape=input_shape) # The Stem Group x = self.stem(inputs) # The Learner outputs = self.learner(x, groups=groups, dropout=dropout) # The Classifier if include_top: outputs = self.classifier(outputs, n_classes) self._model = Model(inputs, outputs)
def __init__(self, groups=None, alpha=1, pho=1, dropout=0.5, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a Mobile Convolution Neural Network alpha : width multipler pho : resolution multiplier input_shape : the input shape n_classes : number of output classes include_top : whether to include classifier initializer : kernel initializer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to include bias """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) if groups is None: groups = list(self.groups) if alpha < 0 or alpha > 1: raise Exception("MobileNet: alpha out of range") if pho < 0 or pho > 1: raise Exception("MobileNet: pho out of range") if dropout < 0 or dropout > 1: raise Exception("MobileNet: alpha out of range") inputs = Input(shape=(int(input_shape[0] * pho), int(input_shape[1] * pho), 3)) # The Stem Group x = self.stem(inputs, alpha=alpha) # The Learner outputs = self.learner(x, groups=groups, alpha=alpha) # The Classifier if include_top: outputs = self.classifier(outputs, n_classes, alpha=alpha, dropout=dropout) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, n_layers, cardinality=32, ratio=16, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a Residual Next Convolution Neural Network n_layers : number of layers cardinality : width of group convolution ratio : amount of filter reduction in squeeze operation input_shape : the input shape n_classes : number of output classes include_top : whether to include classifier initializer : kernel initializer regularizer : kernel regularization relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias with batchnorm """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # predefined if isinstance(n_layers, int): if n_layers not in [50, 101, 152]: raise Exception("SE-ResNeXt: Invalid value for n_layers") groups = list(self.groups[n_layers]) # user defined else: groups = n_layers # The input tensor inputs = Input(shape=input_shape) # The Stem Group x = self.stem(inputs) # The Learner outputs = self.learner(x, groups=groups, cardinality=cardinality, ratio=ratio) # The Classifier if include_top: # Add hidden dropout outputs = self.classifier(outputs, n_classes, dropout=0.0) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, n_layers, n_filters=32, reduction=0.5, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a Densely Connected Convolution Neural Network n_layers : number of layers n_filters : number of filters (growth rate) reduction : anount to reduce feature maps by (compression factor) input_shape : input shape n_classes : number of output classes include_top : whether to include the classifier regularizer : kernel regularizer initializer : kernel initializer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # predefined if isinstance(n_layers, int): if n_layers not in [121, 169, 201]: raise Exception("DenseNet: Invalid value for n_layers") groups = list(self.groups[n_layers]) # user defined else: groups = n_layers # The input vector inputs = Input(shape=input_shape) # The Stem Convolution Group x = self.stem(inputs, n_filters) # The Learner outputs = self.learner(x, n_filters=n_filters, reduction=reduction, groups=groups) # The Classifier if include_top: # Add hidden dropout layer outputs = self.classifier(outputs, n_classes, dropout=0.1) # Instantiate the model self._model = Model(inputs, outputs)
def __init__(self, groups=None, filters=None, n_partitions=2, reduction=0.25, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): ''' Construct a Shuffle Convolution Neural Network groups : number of shuffle blocks per shuffle group filters : filters per group based on partitions n_partitions: number of groups to partition the filters (channels) reduction : dimensionality reduction on entry to a shuffle block input_shape : the input shape to the model n_classes : number of output classes include_top : whether to include classifier initializer : kernel initializer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias in conjunction with batch norm ''' Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) if groups is None: groups = list(ShuffleNet.groups) if filters is None: filters = self.filters[n_partitions] # input tensor inputs = Input(shape=input_shape) # The Stem convolution group (referred to as Stage 1) x = self.stem(inputs) # The Learner outputs = self.learner(x, groups=groups, n_partitions=n_partitions, filters=filters, reduction=reduction) # The Classifier if include_top: # Add hidden dropout to classifier outputs = self.classifier(outputs, n_classes, dropout=0.0) self._model = Model(inputs, outputs)
def __init__(self, n_layers, stem={ 'n_filters': [32, 64], 'pooling': 'feature' }, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a Jump Convolutional Neural Network n_layers : number of layers stem : number of filters in the stem convolutional stack input_shape : input shape n_classes : number of output classes include_top : whether to include classifier regulalizer : kernel regularizer relu_clip : max value for ReLU initializer : kernel initializer bn_epsilon : epsilon for batch norm use_bias : whether to use bias with batchnorm """ # Configure the base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # predefined if isinstance(n_layers, int): if n_layers not in [50, 101, 152]: raise Exception("JumpNet: Invalid value for n_layers") groups = list(self.groups[n_layers]) # user defined else: groups = n_layers # The input tensor inputs = Input(input_shape) # The stem convolutional group x = self.stem(inputs, stem=stem) # The learner outputs = self.learner(x, groups=groups) # The classifier # Add hidden dropout for training-time regularization if include_top: outputs = self.classifier(outputs, n_classes) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, groups=None, alpha=1, expansion=6, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a Mobile Convolution Neural Network V2 groups : number of filters and blocks per group alpha : width multiplier expansion : multiplier to expand the number of filters input_shape : the input shape n_classes : number of output classes include_top : whether to include classifier regularizer : kernel regularizer initializer : kernel initializer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use a bias """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) if groups is None: groups = list(self.groups) inputs = Input(shape=input_shape) # The Stem Group x = self.stem(inputs, alpha=alpha) # The Learner outputs = self.learner(x, groups=groups, alpha=alpha, expansion=expansion) # The Classifier # Add hidden dropout layer if include_top: outputs = self.classifier(outputs, n_classes, dropout=0.0) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, n_layers, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a Residual Convolutional Neural Network V2 n_layers : number of layers input_shape : input shape n_classes : number of output classes include_top : whether to include classifier regularizer : kernel regularizer initializer : kernel initializer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to include a bias with batchnorm """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # predefined if isinstance(n_layers, int): if n_layers not in [50, 101, 152]: raise Exception("ResNet: Invalid value for n_layers") groups = self.groups[n_layers] # user defined else: groups = n_layers # The input tensor inputs = Input(input_shape) # The stem convolutional group x = self.stem(inputs) # The learner outputs = self.learner(x, groups=groups) # The classifier if include_top: # Add hidden dropout for training-time regularization outputs = self.classifier(outputs, n_classes, dropout=0.0) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, groups, alpha=1, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a Mobile Convolution Neural Network V3 groups : number of filters and blocks per group alpha : width multiplier input_shape : the input shape n_classes : number of output classes include_top : whether to include classifier regularizer : kernel regularizer initializer : kernel initializer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # Variable Binding self.GROUPS() # predefined if isinstance(groups, str): if groups not in ['large', 'small']: raise Exception("MobileNetV3: Invalid value for groups") groups = list(self.groups[groups]) inputs = Input(shape=input_shape) # The Stem Group x = self.stem(inputs, alpha=alpha) # The Learner outputs = self.learner(x, groups=groups, alpha=alpha) # The Classifier if include_top: outputs = self.classifier(outputs, n_classes) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, n_layers, ratio=16, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a Residual Convolutional Neural Network V1 n_layers : number of layers input_shape : input shape n_classes : number of output classes include_top : whether to include classifier reg : kernel regularizer init_weights: kernel initializer relu : max value for ReLU bias : whether to use bias for batchnorm """ Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # predefined if isinstance(n_layers, int): if n_layers not in [50, 101, 152]: raise Exception("SE-ResNet: Invalid value for n_layers") groups = list(self.groups[n_layers]) # user defined else: groups = n_layers # The input tensor inputs = Input(shape=input_shape) # The Stem Group x = self.stem(inputs) # The Learner outputs = self.learner(x, groups=groups, ratio=ratio) # The Classifier if include_top: # Add hidden dropout outputs = self.classifier(outputs, n_classes, dropout=0.0) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, n_layers, input_shape=(32, 32, 3), n_classes=10, include_top=True, **hyperparameters): """ Construct a Residual Convolutional Neural Network V1 n_layers : number of layers input_shape : input shape n_classes : number of output classes include_top : whether to include classifier regularizer : kernel regularizer relu_clip : max value for ReLU initializer : kernel initializer bn_epsilon : epsilon for batch norm use_bias : whether to use bias with batchnorm """ # Configure the base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # depth if isinstance(n_layers, int): if n_layers not in [20, 32, 44, 56, 110, 164]: raise Exception("ResNet CIFAR: invalid value for n_layers") groups = list(self.groups[n_layers]) else: groups = n_layers # The input tensor inputs = Input(input_shape) # The stem convolutional group x = self.stem(inputs) # The learner outputs = self.learner(x, groups=groups) # The classifier if include_top: outputs = self.classifier(outputs, n_classes) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, groups=None, input_shape=(572, 572, 3), n_classes=2, include_top=True, **hyperparameters): """ Construct a U-Net Convolutiuonal Neural Network groups : contracting path groups input_shape : input shape n_classes : number of output classes include_top : whether to include classifier initializer : kernel initializer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias with batchnorm """ # Configure the base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # Predefined if groups is None: groups = self.groups # The input tensor inputs = Input(input_shape) # The stem convolutional group x = self.stem(inputs) # The learner outputs = self.learner(x, groups=groups) # The classifier # Add hidden dropout for training-time regularization if include_top: outputs = self.classifier(outputs, n_classes, dropout=0.0) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, n_layers, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct a VGG model n_layers : number of layers (16 or 19) or metaparameter for blocks input_shape : input shape to the model n_classes: : number of output classes include_top : whether to include classifier initializer : kernel initializer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias """ # Configure the base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) # predefined if isinstance(n_layers, int): if n_layers not in [16, 19]: raise Exception("VGG: Invalid value for n_layers") blocks = list(self.groups[n_layers]) # user defined else: blocks = n_layers # The input vector inputs = Input(input_shape) # The stem group x = self.stem(inputs) # The learner outputs = self.learner(x, blocks=blocks) # The classifier if include_top: outputs = self.classifier(outputs, n_classes) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, entry=None, middle=None, input_shape=(229, 229, 3), n_classes=1000, include_top=True, **hyperparameters): """ Construct an Xception Convolution Neural Network entry : number of blocks/filters for entry module middle : number of blocks/filters for middle module input_shape : the input shape n_classes : number of output classes include_top : whether to include classifier initializer : kernel initializer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias in conjunction with batch norm """ Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) if entry is None: entry = self.entry if middle is None: middle = self.middle # Create the input vector inputs = Input(shape=input_shape) # Create entry section with three blocks x = self.entryFlow(inputs, blocks=entry) # Create the middle section with eight blocks x = self.middleFlow(x, blocks=middle) # Create the exit section outputs = self.exitFlow(x, n_classes, include_top) # Instantiate the model self._model = Model(inputs, outputs)
def __init__(self, latent=100, input_shape=(28, 28, 1), **hyperparameters): """ Construct a Deep Convolutional GAN (DC-GAN) latent : dimension of latent space input_shape : input shape initializer : kernel initializer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch normalization use_bias : whether to include bias """ Composable.__init__(self, input_shape, None, self.hyperparameters, **hyperparameters) # Construct the generator self.g = self.generator(latent=latent, height=input_shape[0], channels=input_shape[2]) # Construct the discriminator self.d = self.discriminator(input_shape=input_shape, optimizer=Adam(0.0002, 0.5)) # Construct the combined (stacked) generator/discriminator model (GAN) self.model = self.gan(latent=latent, optimizer=Adam(0.0002, 0.5))
def __init__(self, groups=None, depth=16, k=8, dropout=0, input_shape=(32, 32, 3), n_classes=10, include_top=True, **hyperparameters): """ Construct a Wide Residual (Convolutional Neural) Network depth : number of layers k : width factor groups : number of filters per group input_shape : input shape n_classes : number of output classes include_top : whether to include classifier initializer : kernel initialization regularizer : kernel regularization relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether use bias in conjunction with batch norm """ # Configure base (super) class Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) if groups is None: groups = list(self.groups) # The input tensor inputs = Input(input_shape) # The stem convolutional group x = self.stem(inputs) # The learner outputs = self.learner(x, groups=groups, depth=depth, k=k, dropout=dropout) # The classifier if include_top: # Add hidden dropout outputs = self.classifier(outputs, n_classes, dropout=0.0) # Instantiate the Model self._model = Model(inputs, outputs)
def __init__(self, input_shape=(105, 105, 3), **hyperparameters): """ Construct a Siamese Twin Neural Network input_shape : input shape initializer : kernel initializer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm use_bias : whether to use bias in conjunction with batch norm """ # Configure the base (super) class Composable.__init__(self, input_shape, None, self.hyperparameters, **hyperparameters) # Build the twin model twin = self.twin(input_shape) # Create input tensors for the left and right side (twins) of the network. left_input = Input(input_shape) right_input = Input(input_shape) # Create the encoders for the left and right side (twins) left = twin( left_input ) right = twin( right_input ) # Use Lambda method to create a custom layer for implementing a L1 distance layer. L1Distance = Lambda(lambda tensors:K.abs(tensors[0] - tensors[1])) # Connect the left and right twins (via encoders) to the layer that calculates the # distance between the encodings. connected = L1Distance([left, right]) # Create the output layer for predicting the similarity from the distance layer outputs = self.Dense(connected, 1,activation='sigmoid', kernel_initializer=dense_weights, bias_initializer=biases) # Create the Siamese Network model # Connect the left and right inputs to the outputs self._model = Model(inputs=[left_input,right_input],outputs=outputs)
def __init__(self, groups=None, dropout=0.5, input_shape=(224, 224, 3), n_classes=1000, include_top=True, **hyperparameters): ''' Construct a SqueezeNet Convolutional Neural Network dropout : percent of dropout groups : number of filters per block in groups input_shape : input shape to the model n_classes : number of output classes include_top : whether to include classifier initializer : kernel initializer regularizer : kernel regularizer relu_clip : max value for ReLU bn_epsilon : epsilon for batch norm bias : whether to use bias in conjunction with batch norm ''' # Configure base (super) model Composable.__init__(self, input_shape, include_top, self.hyperparameters, **hyperparameters) if groups is None: groups = list(SqueezeNet.groups) # The input shape inputs = Input(shape=input_shape) # The Stem Group x = self.stem(inputs) # The Learner outputs = self.learner(x, groups=groups, dropout=dropout) # The Classifier if include_top: outputs = self.classifier(outputs, n_classes) # Instantiate the Model self._model = Model(inputs, outputs)