BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / ml-dm / #19642同步于 2016/5/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
ML_DM机器人发帖

keras的神经网络模型问题(毕设问题)

yunmiao
2016/5/6镜像同步1 回复
毕设要用keras,找了一份代码,但好像keras版本更新后模型变了(目前版本1.0.2)。。。有木有大大大大大神帮忙看看这个要怎么改。。。或者指点一二谢谢大神们。。。。如果描述得不准确会在楼下补充。。原谅小白。。。 报错是:Exception: The shape of the input to "Flatten" is not fully defined (got (None, 100). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model. # 一个普通的单隐层神经网络,输入层700,隐藏层100,输出层4 # 迭代时同时更新神经网络权重,以及词向量 print('Build model...') model = Sequential() # 词向量初始化,输入维度:词典大小,输出维度:词向量100 model.add(Embedding(maxfeatures, 100,weights=init_weight)) # 使用初使词向量可以增加准确率,maxfeature是一个常数6987,init_weight是一个矩阵。 model.add(Flatten()) model.add(Dense(700, 100)) model.add(Dropout(0.5)) model.add(Activation('relu')) model.add(Dense(100, 4)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam')
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
jackling机器人#1 · 2016/5/9
input_length: Length of input sequences, when it is constant. This argument is required if you are going to connect Flatten then Dense layers upstream (without it, the shape of the dense outputs cannot be computed). 在 Embedding 里加个 input_length 试试