def get_model():
    from donkeycar.parts.keras import Input, Convolution2D, Dropout, Dense, Flatten, Model
    drop = 0.1

    img_in = Input(shape=(256, 256, 3), name='img_in')
    x = img_in
    x = Convolution2D(24, (5, 5), strides=(2, 2), activation='relu', name="conv2d_1")(x)
    x = Dropout(drop)(x)
    x = Convolution2D(32, (5, 5), strides=(2, 2), activation='relu', name="conv2d_2")(x)
    x = Dropout(drop)(x)
    x = Convolution2D(64, (5, 5), strides=(2, 2), activation='relu', name="conv2d_3")(x)
    x = Dropout(drop)(x)
    x = Convolution2D(64, (3, 3), strides=(1, 1), activation='relu', name="conv2d_4")(x)
    x = Dropout(drop)(x)
    x = Convolution2D(64, (3, 3), strides=(1, 1), activation='relu', name="conv2d_5")(x)
    x = Dropout(drop)(x)

    x = Flatten(name='flattened')(x)
    x = Dense(100, activation='relu')(x)
    x = Dropout(drop)(x)
    x = Dense(50, activation='relu')(x)
    x = Dropout(drop)(x)

    outputs = [
        Dense(1, activation='linear', name='n_outputs0')(x)
    ]

    # for i in range(2):
    #   outputs.append(Dense(1, activation='linear', name='n_outputs' + str(i))(x))

    return Model(inputs=[img_in], outputs=outputs)
Beispiel #2
0
def get_small_epoch_model(input_shape=(66, 200, 3)):
    if not input_shape:
        input_shape = (66, 200, 3)

    img_in = Input(shape=input_shape)
    x = img_in

    # Normalization
    # x = Lambda(lambda x: x / 127.5 - 1.0)(x)
    # x = Lambda(lambda x: x * 255 / 127.5 - 1.0)(x)

    x = Convolution2D(16, (3, 3), activation='relu', padding='same')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2))(x)
    x = Dropout(0.25)(x)

    x = Convolution2D(32, (3, 3), activation='relu', padding='same')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2))(x)
    x = Dropout(0.25)(x)

    x = Convolution2D(64, (3, 3), activation='relu', padding='same')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2))(x)
    x = Dropout(0.5)(x)

    x = Flatten()(x)
    x = Dense(512, activation='relu')(x)
    x = Dropout(.5)(x)

    outputs = get_output_layers(x)

    # for i in range(2):
    #    outputs.append(Dense(1, name='n_outputs' + str(i))(x))

    return Model(inputs=[img_in], outputs=outputs)
Beispiel #3
0
 def get_convolution_kernels(n, kernel_size):
     return Convolution2D(n,
                          kernel_size,
                          kernel_initializer="he_normal",
                          bias_initializer="he_normal",
                          activation='relu',
                          padding='same')
Beispiel #4
0
def get_default_donkeycar_model(input_shape=(140, 320, 3)):
    if not input_shape:
        input_shape = (140, 320, 3)

    drop = 0.1

    img_in = Input(shape=input_shape, name='img_in')
    x = img_in
    x = Convolution2D(24, (5, 5),
                      strides=(2, 2),
                      activation='relu',
                      name="conv2d_1")(x)
    x = Dropout(drop)(x)
    x = Convolution2D(32, (5, 5),
                      strides=(2, 2),
                      activation='relu',
                      name="conv2d_2")(x)
    x = Dropout(drop)(x)
    x = Convolution2D(64, (5, 5),
                      strides=(2, 2),
                      activation='relu',
                      name="conv2d_3")(x)
    x = Dropout(drop)(x)
    x = Convolution2D(64, (3, 3),
                      strides=(1, 1),
                      activation='relu',
                      name="conv2d_4")(x)
    x = Dropout(drop)(x)
    x = Convolution2D(64, (3, 3),
                      strides=(1, 1),
                      activation='relu',
                      name="conv2d_5")(x)
    x = Dropout(drop)(x)

    x = Flatten(name='flattened')(x)
    x = Dense(100, activation='relu')(x)
    x = Dropout(drop)(x)
    x = Dense(50, activation='relu')(x)
    x = Dropout(drop)(x)

    outputs = get_output_layers(x)

    # for i in range(2):
    #   outputs.append(Dense(1, activation='linear', name='n_outputs' + str(i))(x))

    return Model(inputs=[img_in], outputs=outputs)
Beispiel #5
0
def get_dave2_model(input_shape=(66, 200, 3)):
    if not input_shape:
        input_shape = (66, 200, 3)

    img_in = Input(shape=input_shape, name='img_in')
    x = img_in

    # Normalization is carried out in donkey car train data generator
    # x = Lambda(lambda x: x / 127.5 - 1., input_shape=input_shape, name='lambda_norm')(x)
    x = Lambda(lambda x: x * 255 / 127.5 - 1.,
               input_shape=input_shape,
               name='lambda_norm')(x)
    (66, 220)
    # 5x5 Convolutional layers with stride of 2x2
    x = Convolution2D(24, (5, 5),
                      strides=(2, 2),
                      name='conv1',
                      activation='elu')(x)
    x = Convolution2D(36, (5, 5),
                      strides=(2, 2),
                      name='conv2',
                      activation='elu')(x)
    x = Convolution2D(48, (5, 5),
                      strides=(2, 2),
                      name='conv3',
                      activation='elu')(x)

    # 3x3 Convolutional layers with stride of 1x1
    x = Convolution2D(64, (3, 3), name='conv4', activation='elu')(x)
    x = Convolution2D(64, (3, 3), name='conv5', activation='elu')(x)

    # Flatten before passing to Fully Connected layers
    x = Flatten()(x)

    # Three fully connected layers
    x = Dense(100, name='fc1', activation='elu')(x)
    x = Dense(50, name='fc2', activation='elu')(x)
    x = Dense(10, name='fc3', activation='elu')(x)

    # Output layer
    outputs = get_output_layers(x)

    return Model(inputs=[img_in], outputs=outputs)
Beispiel #6
0
def get_chaffeur_model(input_shape=(120, 320, 3)):
    from donkeycar.parts.keras import SpatialDropout2D

    if not input_shape:
        input_shape = (120, 320, 3)

    def get_convolution_kernels(n, kernel_size):
        return Convolution2D(n,
                             kernel_size,
                             kernel_initializer="he_normal",
                             bias_initializer="he_normal",
                             activation='relu',
                             padding='same')

    img_in = Input(shape=input_shape, name='img_in')
    x = img_in

    # (Convolution -> Spatial Dropout -> Max Pooling) x5
    x = Convolution2D(16, (5, 5),
                      input_shape=input_shape,
                      kernel_initializer="he_normal",
                      bias_initializer="he_normal",
                      activation='relu',
                      padding='same')(x)
    x = SpatialDropout2D(0.1)(x)
    x = MaxPooling2D(pool_size=(2, 2))(x)

    x = get_convolution_kernels(20, (5, 5))(x)
    x = SpatialDropout2D(0.1)(x)
    x = MaxPooling2D(pool_size=(2, 2))(x)

    x = get_convolution_kernels(40, (3, 3))(x)
    x = SpatialDropout2D(0.1)(x)
    x = MaxPooling2D(pool_size=(2, 2))(x)

    x = get_convolution_kernels(60, (3, 3))(x)
    x = SpatialDropout2D(0.1)(x)
    x = MaxPooling2D(pool_size=(2, 2))(x)

    x = get_convolution_kernels(80, (2, 2))(x)
    x = SpatialDropout2D(0.1)(x)
    x = MaxPooling2D(pool_size=(2, 2))(x)

    # Flattening and dropping-out
    x = Flatten()(x)
    x = Dropout(0.5)(x)

    # Classification
    outputs = get_output_layers(x)

    # for i in range(2):
    #    outputs.append(Dense(1, name='n_outputs' + str(i), kernel_initializer='he_normal')(x))

    return Model(inputs=[img_in], outputs=outputs)