在Keras 2.0中使用合并

时间:2018-12-21 06:56:16

标签: deep-learning keras-layer keras-2

我关注了以下链接: https://github.com/mayanksatnalika/ipython/blob/master/embeddings%20project/safe_driver/Safe_driver_Kaggle.ipynb

但出现错误NameError:未定义名称“合并”  当我运行以下代码块时:

from keras.layers import *
from keras.models import *

models = []

for categoical_var in categoical_vars :
  model = Sequential()
  no_of_unique_cat  = df_train[categoical_var].nunique()
  embedding_size = min(np.ceil((no_of_unique_cat)/2), 50 )
  embedding_size = int(embedding_size)
  model.add(  Embedding( no_of_unique_cat+1, embedding_size, input_length = 1 ) )
  model.add(Reshape(target_shape=(embedding_size,)))
  models.append( model )


  model_rest = Sequential()
  model_rest.add(Dense(16, input_dim= 43 ))
  models.append(model_rest)

  full_model = Sequential()
  full_model.add(Merge(models, mode='concat'))
  full_model.add(Dense(1000))
  full_model.add(Activation('relu'))
  full_model.add(Dense(400))
  full_model.add(Activation('relu'))
  full_model.add(Dense(200))
  full_model.add(Activation('sigmoid'))

  full_model.add(Dense(2))
  full_model.add(Activation('sigmoid'))
  full_model.compile(loss='binary_crossentropy', optimizer='adam',metrics=['accuracy'])

我是keras的新手,所以跟随了许多行家。似乎Keras 2.0不支持Merge,尝试了很多事情,但无法正常工作。

How to "Merge" Sequential models in Keras 2.0?Keras - Merging layers - Keras 2.0这两个上都遵循了stackoverflow,但没有帮助。

0 个答案:

没有答案