Keras: 2D input -> 2D output?

风格不统一 提交于 2019-12-24 13:29:56

问题


I want to build a neural network to learn a set of standard feature vectors. The set is thus of shape (N,100), where N is the number of samples. However, set of labels is of shape (Nx18) (e.g. each "label" is another array of 18 elements). I'm quite new to keras and neural nets, and I only know how to deal with the label when it is one dimensional (e.g. 0 or 1 in binary classification). How do I can deal with multi-dimensional output?

Thanks!


回答1:


Maybe I don't completely understand the question but the simplest way would be to have an output layer with 18 neuron. Each neuron output one value, i.e. the output will be a vector of 18 values.

One possible way of doing this would be a feed-forward neural network with on hidden layer, e.g. containing 100 neurons. You will need the Dense layer in Keras for this.

nb_hidden = 100

model = Sequential()
model.add(Dense(input_dim = 100, output_dim = nb_hidden)
model.add(Dense(output_dim = 18, activation = 'softmax')
model.compile(loss='categorical_crossentropy', optimizer='adadelta')

Consider varying the number of hidden layers, the general network topology (e.g. include a Dropout layer) and the activation functions until you get a good result.



来源:https://stackoverflow.com/questions/36293208/keras-2d-input-2d-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!