Ejemplo n.º 1
0
def get_fc_layer(x, size, bn=False):
    x = Dense(size, activation='linear',
              kernel_initializer=initializers.glorot_uniform())(x)
    x = ELU()(x)

    if bn:
        x = BatchNormalization()(x)
    x = Dropout(0.50)(x)
    
    return x
def newModel11():
    '''
    https://chatbotslife.com/using-augmentation-to-mimic-human-driving-496b569760a9
    '''

    model = pre_process_layers()
    model.add(Convolution2D(3, 1, 1, border_mode='valid', init='he_normal'))
    model.add(ELU())

    model.add(Convolution2D(32, 3, 3, border_mode='valid', init='he_normal'))
    model.add(ELU())
    model.add(Convolution2D(32, 3, 3, border_mode='valid', init='he_normal'))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.5))

    model.add(Convolution2D(64, 3, 3, border_mode='valid', init='he_normal'))
    model.add(ELU())
    model.add(Convolution2D(64, 3, 3, border_mode='valid', init='he_normal'))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.5))

    model.add(Convolution2D(128, 3, 3, border_mode='valid', init='he_normal'))
    model.add(ELU())
    model.add(Convolution2D(128, 3, 3, border_mode='valid', init='he_normal'))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.5))
    model.add(Flatten())

    model.add(Dense(512, init='he_normal'))
    model.add(ELU())
    model.add(Dropout(0.5))
    model.add(Dense(64, init='he_normal'))
    model.add(ELU())
    model.add(Dropout(0.5))
    model.add(Dense(16, init='he_normal'))
    model.add(ELU())
    model.add(Dropout(0.5))
    model.add(Dense(1, init='he_normal'))

    return model
Ejemplo n.º 3
0
 def activation(x, activation_type = 'relu'):
     if activation_type == 'relu':
         out = ReLU()(x)
         return out
     elif activation_type == 'leakyrelu':
         out = LeakyReLU()(x)
         return out
     elif activation_type == 'elu':
         out = ELU()(x)
         return out
Ejemplo n.º 4
0
def model_build_fcnn4(n_classes):
    input_shape = (96, 1366)

    model = Sequential(name='fcnn4')

    model.add(
        Reshape(target_shape=input_shape + (1, ), input_shape=input_shape))
    model.add(ZeroPadding2D(padding=(0, 37)))

    model.add(BatchNormalization(axis=3))

    model.add(Conv2D(filters=32, kernel_size=(3, 3), padding='same'))
    model.add(BatchNormalization(axis=3))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 5)))
    model.add(Dropout(rate=0.25))

    model.add(Conv2D(filters=64, kernel_size=(3, 3), padding='same'))
    model.add(BatchNormalization(axis=3))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(3, 6)))
    model.add(Dropout(rate=0.25))

    model.add(Conv2D(filters=128, kernel_size=(3, 3), padding='same'))
    model.add(BatchNormalization(axis=3))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(4, 6)))
    model.add(Dropout(rate=0.25))

    model.add(Conv2D(filters=256, kernel_size=(3, 3), padding='same'))
    model.add(BatchNormalization(axis=3))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(4, 8)))
    model.add(Dropout(rate=0.25))

    model.add(Flatten())
    model.add(BatchNormalization(axis=1))
    model.add(Dropout(rate=0.5))
    model.add(Dense(units=n_classes, activation='sigmoid'))

    model_compiler(model)

    return model
def origin_EEG_net(num_classes, chans=22, samples=768):
    '''
    original EEGnet
    '''
    data_shape = (3, chans, samples)
    model = Sequential()
    model.add(
        Conv2D(4, (1, 64),
               data_format='channels_first',
               padding='same',
               use_bias=False,
               input_shape=data_shape))

    model.add(BatchNormalization(axis=1))

    model.add(
        DepthwiseConv2D((chans, 1),
                        data_format='channels_first',
                        use_bias=False,
                        depth_multiplier=2,
                        depthwise_constraint=max_norm(1.)))

    model.add(BatchNormalization(axis=1))
    model.add(ELU())
    model.add(AveragePooling2D((1, 4), data_format='channels_first'))
    model.add(Dropout(0.25))

    model.add(
        SeparableConv2D(8, (1, 16),
                        use_bias=False,
                        padding='same',
                        data_format='channels_first'))

    model.add(BatchNormalization(axis=1))
    model.add(ELU())
    model.add(AveragePooling2D((1, 8), data_format='channels_first'))
    model.add(Dropout(0.25))
    model.add(Flatten())
    model.add(
        Dense(num_classes,
              activation='softmax',
              kernel_constraint=max_norm(0.25)))
    return model
Ejemplo n.º 6
0
def define_encoder_block(layer_in, n_filters, batchnorm=True):
    init = RandomNormal(stddev=0.02)
    g = Conv2D(n_filters, (4, 4),
               strides=(2, 2),
               padding='same',
               kernel_initializer=init)(layer_in)
    if batchnorm:
        g = BatchNormalization()(g, training=True)
    g = ELU(alpha=0.2)(g)
    return g
Ejemplo n.º 7
0
    def build_model(self, xDiv_, yDiv_):

        input_height = int(self._data_parser.img_height / yDiv_)
        input_width = int(self._data_parser.img_width / xDiv_)
        input_channels = self._data_parser.img_channels

        self._model = Sequential()

        # normalize -1<>+1
        self._model.add(
            Lambda(lambda x: x / 127.5 - 1.,
                   input_shape=(input_height, input_width, input_channels),
                   output_shape=(input_height, input_width, input_channels)))

        # Conv Layer #0 (depth=3, kernel=1x1) - change color space
        self._model.add(Convolution2D(3, 1, 1, border_mode='same'))

        # Conv Layer #1 (depth=24, kernel=5x5)
        self._model.add(Convolution2D(24, 5, 5, border_mode='valid'))
        self._model.add(ELU())
        self._model.add(MaxPooling2D(pool_size=(2, 2)))
        self._model.add(Dropout(0.5))

        # Conv Layer #2 (depth=36, kernel=5x5)
        self._model.add(Convolution2D(36, 5, 5, border_mode='valid'))
        self._model.add(ELU())
        self._model.add(MaxPooling2D(pool_size=(2, 2)))
        self._model.add(Dropout(0.5))

        # Conv Layer #3 (depth=48, kernel=3x3)
        self._model.add(Convolution2D(48, 3, 3, border_mode='valid'))
        self._model.add(ELU())
        self._model.add(MaxPooling2D(pool_size=(2, 2)))
        self._model.add(Dropout(0.5))

        # Conv Layer #4 (depth=64, kernel=3x3)
        self._model.add(Convolution2D(64, 3, 3, border_mode='valid'))
        self._model.add(ELU())
        self._model.add(MaxPooling2D(pool_size=(2, 2)))
        self._model.add(Dropout(0.5))

        self._model.add(Flatten())

        # Hidden Layer #1
        self._model.add(Dense(100))
        self._model.add(ELU())

        # Hidden Layer #2
        self._model.add(Dense(50))
        self._model.add(ELU())

        # Hidden Layer #3
        self._model.add(Dense(10))
        self._model.add(ELU())

        # Answer
        self._model.add(Dense(1))
        self._model.summary()
Ejemplo n.º 8
0
def get_model():
    model = Sequential()
    # model.add(Lambda(preprocess_batch, input_shape=(160, 320, 3), output_shape=(64, 64, 3)))

    # layer 1 output shape is 32x32x32
    model.add(
        Convolution2D(32,
                      5,
                      5,
                      input_shape=(64, 64, 3),
                      subsample=(2, 2),
                      border_mode="same"))
    model.add(ELU())

    # layer 2 output shape is 15x15x16
    model.add(Convolution2D(16, 3, 3, subsample=(1, 1), border_mode="valid"))
    model.add(ELU())
    model.add(Dropout(.4))
    model.add(MaxPooling2D((2, 2), border_mode='valid'))

    # layer 3 output shape is 12x12x16
    model.add(Convolution2D(16, 3, 3, subsample=(1, 1), border_mode="valid"))
    model.add(ELU())
    model.add(Dropout(.4))

    # Flatten the output
    model.add(Flatten())

    # layer 4
    model.add(Dense(1024))
    model.add(Dropout(.3))
    model.add(ELU())

    # layer 5
    model.add(Dense(512))
    model.add(ELU())

    # Finally a single output, since this is a regression problem
    model.add(Dense(1))

    model.compile(optimizer="adam", loss="mse")

    return model
Ejemplo n.º 9
0
def model_config():
    model = Sequential()

    model.add(Lambda(lambda x: (x / 255) - 0.5, input_shape=(160, 320, 3)))
    model.add(Cropping2D(cropping=((70, 25), (0, 0))))

    model.add(Conv2D(3, (1, 1), padding='same'))
    model.add(ELU())

    model.add(BatchNormalization())
    model.add(Conv2D(16, (5, 5), strides=(2, 2), padding="same"))
    model.add(ELU())

    model.add(BatchNormalization())
    model.add(Conv2D(32, (5, 5), strides=(2, 2), padding="same"))
    model.add(ELU())

    model.add(BatchNormalization())
    model.add(Conv2D(64, (3, 3), strides=(2, 2), padding="same"))
    model.add(ELU())

    model.add(BatchNormalization())
    model.add(Conv2D(128, (3, 3), strides=(2, 2), padding="same"))
    model.add(ELU())

    model.add(Flatten())
    model.add(ELU())

    model.add(Dense(512))
    model.add(Dropout(.2))
    model.add(ELU())

    model.add(Dense(100))
    model.add(Dropout(.5))
    model.add(ELU())

    model.add(Dense(10))
    model.add(Dropout(.5))
    model.add(ELU())

    model.add(Dense(1))

    adam = Adam(lr=1e-5)
    model.compile(optimizer=adam, loss="mse", metrics=['accuracy'])

    model.summary()

    return model
Ejemplo n.º 10
0
def build_nvidia_paper_model(sensor_count,
                             single_sensor_input_shape,
                             overfit_training=False):
    sensor_inputs = []
    sensor_outputs = []

    for sensor_id in range(0, sensor_count):
        #Q Will it if we make input_sensor = Input() and then appent list.append(input_sensor) 3 times. will it be same data or different for eact sensor?
        #Q How to do this as an array?
        single_sensor_input = Input(shape=single_sensor_input_shape)
        single_sensor_output = build_single_sensor_network(single_sensor_input)

        sensor_inputs.append(single_sensor_input)
        sensor_outputs.append(single_sensor_output)

    ### To Do: Enable Batch Normalisation back
    x = concatenate(sensor_outputs)
    x = Flatten()(x)

    if overfit_training == False:
        x = Dropout(.5)(x)

    x = Dense(100)(x)
    x = Dropout(.5)(x)
    x = ELU()(x)

    x = Dense(50)(x)
    x = Dropout(.5)(x)
    x = ELU()(x)

    x = Dense(10)(x)
    x = ELU()(x)

    x = Dense(1)(x)
    x = ELU()(x)

    x = Dense(1, activation='tanh')(x)
    #x = SeparableConv1D(5,1)(x)

    model = Model(inputs=sensor_inputs, outputs=x)
    #model.summary()
    #show_model(model) #To Do: install pydot on google colab and do this
    return model
Ejemplo n.º 11
0
        def get_conv_layer(emb, kernel_size=5, filters=256):
            # Conv layer
            conv = Convolution1D(kernel_size=kernel_size, filters=filters, \
                                 border_mode='same')(emb)
            conv = ELU()(conv)

            conv = Lambda(sum_1d, output_shape=(filters, ))(conv)
            # conv = BatchNormalization(mode=0)(conv)
            conv = Dropout(0.5)(conv)
            return conv
 def get_conv_layer(emb, kernel_size=5, filters=256):
     # Conv layer
     conv = Convolution1D(kernel_size=kernel_size,
                          filters=filters,
                          border_mode='same')(emb)
     conv = ELU()(conv)
     conv = MaxPooling1D(5)(conv)
     conv = Lambda(sum_1d, output_shape=(filters, ))(conv)
     conv = Dropout(0.5)(conv)
     return conv
Ejemplo n.º 13
0
    def test_elu(self):
        keras_model = Sequential()
        keras_model.add(ELU(input_shape=(3, 32, 32), name='elu'))
        keras_model.compile(loss=keras.losses.categorical_crossentropy,
                            optimizer=keras.optimizers.SGD())

        pytorch_model = ELUNet()

        self.transfer(keras_model, pytorch_model)
        self.assertEqualPrediction(keras_model, pytorch_model, self.test_data)
Ejemplo n.º 14
0
    def call(self, input):

        outputs = []

        for i in range(self.num_attention_heads):

            if self.num_filters is not None:
                conv_out = dfnets_graph_conv(input, self.num_filters,
                                             self.arma_conv_AR,
                                             self.arma_conv_MA,
                                             self.input_signal,
                                             self.ar_kernels[i],
                                             self.ma_kernels[i])
            else:
                conv_out = K.dot(input, self.kernels[i])

            if self.use_bias:
                conv_out = K.bias_add(conv_out, self.kernels_biases[i])

            atten_conv_out_self = K.dot(
                conv_out, self.attention_kernels[i][:self.output_dim])
            atten_conv_out_neigh = K.dot(
                conv_out, self.attention_kernels[i][self.output_dim:])

            if self.use_bias:
                atten_conv_out_self = K.bias_add(
                    atten_conv_out_self, self.attention_kernels_biases[i])

            atten_coeff_matrix = atten_conv_out_self + K.transpose(
                atten_conv_out_neigh)
            atten_coeff_matrix = ELU(alpha=1.0)(
                atten_coeff_matrix)  #LeakyReLU(alpha=0.2)

            mask = K.exp(self.adjacency_matrix * -10e9) * -10e9
            atten_coeff_matrix = atten_coeff_matrix + mask

            atten_coeff_matrix = K.softmax(atten_coeff_matrix)
            atten_coeff_matrix = Dropout(
                self.attention_dropout)(atten_coeff_matrix)

            node_feature_matrix = K.dot(atten_coeff_matrix, conv_out)

            if self.attention_combine == 'concat' and self.activation is not None:
                node_feature_matrix = self.activation(node_feature_matrix)

            outputs.append(node_feature_matrix)

        if self.attention_combine == 'concat':
            output = K.concatenate(outputs)
        else:
            output = K.mean(K.stack(outputs), axis=0)
            if self.activation is not None:
                output = self.activation(output)

        return output
Ejemplo n.º 15
0
def get_model(time_len=1):
    ch, row, col = 3, img_size_y, img_size_x

    model = Sequential()

    model.add(
        Lambda(lambda x: x / 255. - 0.5,
               input_shape=(row, col, ch),
               output_shape=(row, col, ch)))

    model.add(Convolution2D(32, 3, 3, border_mode="valid", init=init))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(.5))

    model.add(Convolution2D(64, 3, 3, border_mode="valid", init=init))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(.5))

    model.add(Convolution2D(128, 3, 3, border_mode="valid", init=init))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(.5))

    model.add(Flatten())

    model.add(Dense(512, init=init))
    model.add(ELU())
    model.add(Dropout(.5))

    model.add(Dense(128, init=init))
    model.add(ELU())
    model.add(Dropout(.5))

    model.add(Dense(64, init=init))
    model.add(ELU())
    model.add(Dropout(.5))

    model.add(Dense(32, init=init))
    model.add(ELU())
    model.add(Dropout(.5))

    model.add(Dense(16, init=init))
    model.add(ELU())
    model.add(Dropout(.5))

    model.add(Dense(1, init=init))

    model.compile(optimizer="adam", loss="mse")

    return model
Ejemplo n.º 16
0
def create_model(input_shape=(100, 220, 3)):
    #Setting Keras image dimension sequence to tensorflow
    K.set_image_dim_ordering('tf')
    model = Sequential()
    #Using Nvidia's model

    #normalizing input image
    model.add(Lambda(lambda x: x / 255 - 0.5, input_shape=input_shape))

    #1st layer
    model.add(Convolution2D(24, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(1, 1)))

    #2nd layer
    model.add(Convolution2D(36, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(1, 1)))

    #3rd layer
    model.add(Convolution2D(48, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(1, 1)))

    #4th layer
    model.add(Convolution2D(64, 3, 3, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(1, 1)))

    #5th layer
    model.add(Convolution2D(64, 3, 3, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(1, 1)))

    #Flatten layers
    model.add(Flatten())

    #Fully connected layers
    model.add(Dense(1024))
    model.add(ELU())

    #Fully connected layers
    model.add(Dense(100))
    model.add(ELU())

    #Fully connected layers
    model.add(Dense(50))
    model.add(ELU())
    #Fully connected layer with single output
    model.add(Dense(1))

    return model
Ejemplo n.º 17
0
def NvidiaModel(learning_rate, dropout):
    input_model = Input(shape=(HEIGHT, WIDTH, DEPTH))
    x = Convolution2D(24,
                      5,
                      5,
                      border_mode='valid',
                      subsample=(2, 2),
                      W_regularizer=l2(learning_rate))(input_model)
    x = ELU()(x)
    x = Convolution2D(36,
                      5,
                      5,
                      border_mode='valid',
                      subsample=(2, 2),
                      W_regularizer=l2(learning_rate))(x)
    x = ELU()(x)
    x = Convolution2D(48,
                      5,
                      5,
                      border_mode='valid',
                      subsample=(2, 2),
                      W_regularizer=l2(learning_rate))(x)
    x = ELU()(x)
    x = Convolution2D(64,
                      3,
                      3,
                      border_mode='valid',
                      subsample=(1, 1),
                      W_regularizer=l2(learning_rate))(x)
    x = ELU()(x)
    x = Convolution2D(64,
                      3,
                      3,
                      border_mode='valid',
                      subsample=(1, 1),
                      W_regularizer=l2(learning_rate))(x)
    x = ELU()(x)
    x = Flatten()(x)
    x = Dense(100)(x)
    x = ELU()(x)
    x = Dropout(dropout)(x)
    x = Dense(50)(x)
    x = ELU()(x)
    x = Dropout(dropout)(x)
    x = Dense(10)(x)
    x = ELU()(x)
    predictions = Dense(1)(x)
    model = Model(input=input_model, output=predictions)
    # model.compile(optimizer='adam', loss='mse')
    model.compile(optimizer='adam', loss=customLoss)  #, metrics=['mse'])
    print(model.summary())
    return model
Ejemplo n.º 18
0
def residual_block(x, outdim, stride, name):
    input_dim = int(x.shape[-1].value)
    shortcut = Conv2D(outdim,
                      kernel_size=(1, 1),
                      strides=stride,
                      name=f'{name}_scut_conv',
                      kernel_regularizer=regularizers.l2(l=c.WEIGHT_DECAY))(x)
    shortcut = BatchNormalization(name=f'{name}_scut_norm')(shortcut)

    for i in range(c.BLOCK_NUM):
        if i > 0:
            stride = 1
            x = Dropout(c.DROPOUT, name=f'{name}_drop{i-1}')(x)

        x = conv_block(x,
                       outdim // 4, (1, 1),
                       stride,
                       name,
                       'a',
                       i,
                       padding='valid')
        x = conv_block(x,
                       outdim // 4, (3, 3), (1, 1),
                       name,
                       'b',
                       i,
                       padding='same')
        x = conv_block(x,
                       outdim, (1, 1), (1, 1),
                       name,
                       'c',
                       i,
                       padding='valid')
        if i != c.BLOCK_NUM - 1:
            x = ELU(name=f'{name}_reluc{i}')(x)
    # add SE
    x = Multiply(name=f'{name}_scale')(
        [x, squeeze_excitation(x, c.REDUCTION_RATIO, name)])
    x = Add(name=f'{name}_scut')([shortcut, x])
    x = ELU(name=f'{name}_relu')(x)
    # x = Activation('relu',name=f'{name}_relu')(x)
    return x
    def model_setup(self):
        print("Setting up the model")
        # ================================================
        image_size = (160, 320, 3)  # Same as source from emulator
        # ================================================
        # CommaAI Model:
        # https://github.com/commaai/research/blob/master/train_steering_model.py
        model = Sequential()
        model.add(
            Lambda(lambda x: x / 127.5 - 1.,
                   input_shape=image_size,
                   output_shape=image_size))
        model.add(Convolution2D(16, 8, 8, subsample=(4, 4),
                                border_mode="same"))
        # -- Experimenting with MaxPooling:
        # model.add(Convolution2D(16, 8, 8, border_mode="same"))
        # model.add(MaxPooling2D(pool_size=(4, 4), border_mode='same'))
        # --
        model.add(ELU())
        model.add(Convolution2D(32, 5, 5, subsample=(2, 2),
                                border_mode="same"))
        model.add(ELU())
        model.add(Convolution2D(64, 5, 5, subsample=(2, 2),
                                border_mode="same"))
        model.add(Flatten())
        model.add(Dropout(.2))
        model.add(ELU())
        model.add(Dense(512))
        model.add(Dropout(.5))
        model.add(ELU())
        model.add(Dense(1))
        # ================================================
        self.model = model

        # self.loss_fn = "mse"
        # optimizer = Adam(lr=0.001)
        self.model.compile(loss="mse", optimizer=Adam(lr=0.0001))
        # self.model.compile(loss="mse", optimizer=Adam(lr=0.001))
        # self.model.compile(loss="mse", optimizer=Adam(lr=0.01))
        # self.model.compile(loss="mse", optimizer=Adam(lr=0.03))

        return self.model
Ejemplo n.º 20
0
    def build_model(self):
        # shared network
        state = Input(shape=[self.state_size])
        state_process = Dense(32,
                              kernel_initializer='he_normal',
                              use_bias=False)(state)
        state_process = BatchNormalization()(state_process)
        state_process = Activation('elu')(state_process)

        # Actor
        policy = Dense(64, kernel_initializer='he_normal',
                       use_bias=False)(state_process)
        policy = BatchNormalization()(policy)
        policy = ELU()(policy)
        policy = Dense(self.action_size,
                       activation='tanh',
                       kernel_initializer=tf.random_uniform_initializer(
                           minval=-3e-3, maxval=3e-3))(policy)
        actor = Model(inputs=state, outputs=policy)

        # Critic
        action = Input(shape=[self.action_size])
        action_process = Dense(32,
                               kernel_initializer='he_normal',
                               use_bias=False)(action)
        action_process = BatchNormalization()(action_process)
        action_process = ELU()(action_process)
        state_action = Add()([state_process, action_process])

        Qvalue = Dense(64, kernel_initializer='he_normal',
                       use_bias=False)(state_action)
        Qvalue = BatchNormalization()(Qvalue)
        Qvalue = ELU()(Qvalue)
        Qvalue = Dense(1,
                       kernel_initializer=tf.random_uniform_initializer(
                           minval=-3e-3, maxval=3e-3))(Qvalue)
        critic = Model(inputs=[state, action], outputs=Qvalue)

        actor._make_predict_function()
        critic._make_predict_function()

        return actor, critic
Ejemplo n.º 21
0
def get_conv_activation(x, name):
    if name == 'relu':
        return Activation('relu')(x)
    elif name == 'elu':
        return ELU()(x)
    elif name == 'prelu':
        return PReLU()(x)
    elif name == 'srelu':
        return SReLU()(x)
    elif name == 'none':
        return x
Ejemplo n.º 22
0
 def f(input):
     conv_output1 = Conv3D(n, (c, w, h),
                           activation='linear',
                           padding='same',
                           kernel_initializer='he_normal')(input)
     act_output1 = ELU(1.0)(conv_output1)
     conv_output2 = Conv3D(n, (c, w, h),
                           activation='linear',
                           padding='same',
                           kernel_initializer='he_normal')(act_output1)
     return BatchNormalization(axis=1)(conv_output2)
Ejemplo n.º 23
0
def deconvBlock(x, filters):

    unpool = UpSampling2D(data_format="channels_last")(x)
    deconv = Conv2DTranspose(filters,
                             3,
                             strides=1,
                             padding='same',
                             data_format="channels_last")(unpool)
    bn = ELU()(BatchNormalization()(deconv))

    return bn
Ejemplo n.º 24
0
def get_activation_layer(activation):
    if activation == 'LeakyReLU':
        return LeakyReLU()
    if activation == 'PReLU':
        return PReLU()
    if activation == 'ELU':
        return ELU()
    if activation == 'ThresholdedReLU':
        return ThresholdedReLU()

    return Activation(activation)
Ejemplo n.º 25
0
def getModel():
    
    model = Sequential()

    model.add(Lambda(lambda x: (x / 127.5) - 1., input_shape=(160, 320, 3)))
    model.add(Cropping2D(cropping=((70, 25), (0, 0)), input_shape=(160, 320, 3)))
    model.add(Convolution2D(16, 8, 8, subsample=(4, 4), border_mode="same"))
    model.add(ELU())
    model.add(Convolution2D(32, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(Convolution2D(64, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(Flatten())
    model.add(Dropout(.2))
    model.add(ELU())
    model.add(Dense(512))
    model.add(Dropout(.5))
    model.add(ELU())
    model.add(Dense(1))
    
    return model
Ejemplo n.º 26
0
def convolution_layer(_in):
    conv1 = Conv2D(256, (3, 3),
                   activation='linear',
                   kernel_regularizer=regularizers.l2(0.0001),
                   padding='same')(_in)

    bn1 = BatchNormalization()(conv1)

    lr1 = ELU()(bn1)

    return lr1
Ejemplo n.º 27
0
def get_model():
    model = Sequential()
    model.add(Lambda(lambda x: x / 127.5 - 1., input_shape=(160, 320, 3)))
    model.add(
        Cropping2D(cropping=((75, 25), (0, 0)), input_shape=(160, 320, 3)))
    model.add(Convolution2D(16, 8, 8, subsample=(4, 4), border_mode="same"))
    model.add(ELU())
    model.add(Convolution2D(32, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(Convolution2D(64, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(Flatten())
    model.add(Dropout(.2))
    model.add(ELU())
    model.add(Dense(512))
    model.add(Dropout(.5))
    model.add(ELU())
    model.add(Dense(1))
    model.summary()
    model.compile(optimizer="adam", loss="mse", metrics=['accuracy'])
    return model
Ejemplo n.º 28
0
def compile_commaai_model():
    model = Sequential()
    model.add(Cropping2D(cropping=INPUT_IMAGE_CROPPING, input_shape=INPUT_IMAGE_SHAPE))
    model.add(Lambda(lambda x: x / 127.5 - 1.))
    model.add(Convolution2D(16, 8, 8, subsample=(4, 4), border_mode="same"))
    model.add(ELU())
    model.add(Convolution2D(32, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(Convolution2D(64, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(Flatten())
    model.add(Dropout(.2))
    model.add(ELU())
    model.add(Dense(512))
    model.add(Dropout(.5))
    model.add(ELU())
    model.add(Dense(1))

    model.compile(optimizer="adam", loss="mse")

    return model
Ejemplo n.º 29
0
def model_comma_elu():
    model = Sequential()
    model.add(
        Lambda(lambda x: x / 127.0 - 1.,
               input_shape=(conf.row, conf.col, conf.ch)))

    model.add(Convolution2D(16, 8, 8, subsample=(4, 4), border_mode="same"))
    model.add(ELU())
    model.add(Convolution2D(32, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(ELU())
    model.add(Convolution2D(64, 5, 5, subsample=(2, 2), border_mode="same"))
    model.add(Flatten())
    model.add(ELU())
    model.add(Dense(512))
    model.add(ELU())
    model.add(Dense(1))

    model.compile(optimizer="adam", loss="mse")

    return model
 def get_model(self, parallel=False):
     model = Sequential()
     #model.add(Lambda(lambda x: x / 127.5 - 1., input_shape=(64, 64, 3)))
     model.add(
         Convolution2D(8,
                       8,
                       8,
                       subsample=(4, 4),
                       border_mode="same",
                       activation='elu',
                       name='Conv1'))
     model.add(
         Convolution2D(16,
                       5,
                       5,
                       subsample=(2, 2),
                       border_mode="same",
                       activation='elu',
                       name='Conv2'))
     model.add(
         Convolution2D(32,
                       5,
                       5,
                       subsample=(2, 2),
                       border_mode="same",
                       activation='elu',
                       name='Conv3'))
     model.add(Flatten())
     model.add(ELU())
     model.add(Dense(1024, activation='elu'))
     model.add(Dropout(.5))
     model.add(ELU())
     model.add(Dense(512, activation='elu'))
     model.add(Dropout(.5))
     model.add(Dense(1, name='output'))
     model.add(Activation('sigmoid'))
     if parallel:
         model = make_parallel(model, 2)
     #model.compile(optimizer='sgd', loss='binary_crossentropy', metrics=['accuracy'])
     self.model = model
     return model