0

have 2 datasets, for the first data set i want to apply convolution and keep the result of flatten layyer then concatenate it with an other data set and a do a simple feed forward it is possible with keras ?

def build_model(x_train,y_train):
    np.random.seed(7)

    left = Sequential()

    left.add(Conv1D(nb_filter= 6, filter_length=3, input_shape= (48,1),activation = 'relu', kernel_initializer='glorot_uniform'))
    left.add(Conv1D(nb_filter= 6,  filter_length=3, activation= 'relu'))
    #model.add(MaxPooling1D())
    print model
    #model.add(Dropout(0.2))
    # flatten layer 
    #https://www.quora.com/What-is-the-meaning-of-flattening-step-in-a-convolutional-neural-network
    left.add(Flatten())


    left.add(Reshape((48,1)))
    right = Sequential()

    #model.add(Reshape((48,1)))
# Compile model

    model.add(Merge([left, right], mode='sum'))
    model.add(Dense(10, 10))
    epochs = 100
    lrate = 0.01
    decay = lrate/epochs
    sgd = SGD(lr=lrate, momentum=0.9, decay=decay, nesterov=False)
              #clipvalue=0.5)
    model.compile(loss='mean_squared_error', optimizer='Adam')
    model.fit(x_train,y_train, nb_epoch =epochs, batch_size=10, verbose=1)

    #model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'] , )

    return model
4
  • I don't understand the question. Does the code you posted work or not? What would you want it to do differently? Commented Jul 17, 2017 at 9:26
  • my code does not working i have 2 datasets but with the same target for the the first dataset i want to apply a convolution and keep the flatten output then concatenate it w with the second datasets and do a simple feedforwad Commented Jul 17, 2017 at 9:29
  • Where exactly does it break? Commented Jul 17, 2017 at 9:33
  • it does not break but i don"t know what should i do in model.fit(x_train,y_train, nb_epoch =epochs, batch_size=10, verbose=1) how can i concatenate the output flatten with and other output how my keras model wil know the datasets used with flatten Commented Jul 17, 2017 at 9:38

1 Answer 1

1

You need to look at the functional API. The sequential model you are using is not designed to take multiple network inputs. Follow the "Multi-input and multi-output models" example and you will have it working in no time!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.