'Tensor'对象没有属性'compile'

时间:2019-01-06 16:18:01

标签: python keras deep-learning keras-2

以下是代码段:

    merged_model = Sequential()
    merged_model = concatenate([model1.output, model2.output, model3.output, model4.output, model5.output])
    x = BatchNormalization()(merged_model)

    x = Dense(300)(x)
    x = PReLU()(x)
    x = Dropout(0.2)(x)
    x = BatchNormalization()(x)

    x = Dense(1)(x)
    out = Activation('sigmoid')(x)

    mergerd_model = Model([model1.input, model2.input, model3.input, model4.input, model5.input], [out])

    merged_model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

    merged_model.fit([x1, x2, x3, x4, x5], y=y, batch_size=384, nb_epoch=20,
             verbose=1, validation_split=0.1, shuffle=True, callbacks=[checkpoint])

但是当我尝试运行它时,出现以下错误:

    Traceback (most recent call last):
  File "t1.py", line 167, in <module>
    merged_model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
AttributeError: 'Tensor' object has no attribute 'compile'

当我尝试查看merged_model的类型时,我得到了:

<class 'tensorflow.python.framework.ops.Tensor'>

1 个答案:

答案 0 :(得分:0)

主要问题是拼写错误:构建模型时,它应该是// prototype for `round()` #include <math.h> do { // coin = get_float("enter the owed change?"); coins = round(100.0 * get_float("enter the owed change?"); printf("\n"); // } while(coin<=0.00 || coin>1.00); } while(coin <= 0 || coin > 100); ... // while((coin-0.10)>0) while((coin - 10) > 0) 而不是merged_model(即删除多余的“ r”)。但是,由于您正在使用Functional API并且可以将其删除,因此以下行也不需要:

mergerd_model