Esempio n. 1
0
def conv1d_model(shape_X, shape_Y, drp=0.3, krnl=(3, 3), dilate=0, mpool=0):
    n_timesteps = shape_X[1]
    n_features = shape_X[2]
    n_outputs = shape_Y[1]

    model = Sequential()

    model.add(Conv1D(filters=16, kernel_size=krnl[0], activation='relu', input_shape=(n_timesteps, n_features)))
    if not dilate:
        model.Name = "1D TCN"
        model.add(Conv1D(filters=16, kernel_size=krnl[1], activation='relu'))
    else:
        model.Name = "1D {} dilated TCN".format(dilate)
        model.add(Conv1D(filters=16, kernel_size=krnl[1], activation='relu', dilation_rate=dilate))
    if mpool:
        model.add(MaxPooling1D(pool_size=mpool))
    model.add(Dropout(drp))
    model.add(Flatten())
    model.add(Dense(100, activation='relu'))
    model.add(Dense(50, activation='relu'))
    model.add(Dense(n_outputs, activation='linear'))
    model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mape'])
    return model
Esempio n. 2
0
def depthwise_model(shape_X, shape_Y, drp=0.3, krnl=(3, 3), dilate=0, mpool=0):
    n_timesteps = shape_X[2]
    n_features = shape_X[3]
    n_outputs = shape_Y[1]

    model = Sequential()
    model.add(DepthwiseConv2D(input_shape=(1, n_timesteps, n_features),
                              kernel_size=(1, krnl[0]),
                              depth_multiplier=4,
                              activation='relu',
                              padding='valid'))
    if mpool:
        model.add(MaxPooling2D(pool_size=(1,mpool)))
    if not dilate:
        model.Name = "1D TCN"
        model.add(DepthwiseConv2D(input_shape=(1, n_timesteps, n_features),
                                  kernel_size=(1, krnl[1]),
                                  depth_multiplier=16,
                                  activation='relu',
                                  padding='valid'))
    else:
        model.Name = "1D {} dilated TCN".format(dilate)
        model.add(DepthwiseConv2D(input_shape=(1, n_timesteps, n_features),
                                  kernel_size=(1, krnl[1]),
                                  dilation_rate=dilate,
                                  depth_multiplier=3,
                                  activation='relu',
                                  padding='valid'))
    if mpool:
        model.add(MaxPooling2D(pool_size=(1,mpool)))
    model.add(Dropout(drp))
    model.add(Flatten())
    model.add(Dense(100, activation='relu'))
    model.add(Dense(50, activation='relu'))
    model.add(Dense(n_outputs, activation='linear'))
    model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mape'])
    return model