from keras.layers import *
from keras.models import Model
# 1. define model parameters
# 1.1 dropout rate, you may want to use 0 first
dropout_rate = 0.2
# 1.2 mlp structure
fc_nodes = [128, 32, 8]
# activation, e.g. relu or tanh
activation = 'relu'
# 2. define model
# 2.1 define input
# note: batch_size=16 is NOT included in shape
feat_in = Input(shape=(1000,), name='feat_in')
# 2.2 define body
x = feat_in
for idx, nb_nodes in enumerate( fc_nodes ) :
x = Dense( nb_nodes, activation=activation, name='fc-{}'.format(idx) )(x)
if ( dropout_rate > 0 ) :
x = Dropout( dropout_rate, name='dropout-{}'.format(idx))(x)
# 2.3 define output
pred_out = Dense( 4, activation='softmax', name='pred_out')(x)
# 2.4 define model
model = Model( inputs=feat_in, outputs=pred_out, name='my_model')
# 3. display model architecture
print model.summary()
我真的很难理解你的问题。你的意思是说你的输入是一个1000维的特征向量,总共有16个,你的网络输出,即目标,是四种可能的疾病之一
如果是这种情况,那么您误解了CNN的输入形状,它的批大小没有被考虑(您可以使用不同的批大小,因此我们希望将此参数与模型解耦)
根据您对1000 dim特征的理解,您需要在将其输入模型之前应用一些特征规范化
该模型将采用
(batch_size, 1000)
形状的二维张量,并预测(batch_size, 4)
形状的二维张量顺便说一句,
Conv2D
应该只在您的输入是类似图像的情况下使用,这不是您的情况相关问题 更多 >
编程相关推荐