【发布时间】:2020-11-12 01:53:16
【问题描述】:
我目前正在使用 Keras + Tensorflow 开发一个模型,以确定一组蛋白质的温度范围。我首先做的是创建一个预训练模型,将蛋白质转换为嵌入,然后预测其各自的温度。
我现在要做的是将此预训练模型合并到一个新模型中,该模型可以使用这个给定模型和相应的权重作为输入。然后适应一个新的数据集并再次预测。新顶级模型的以下代码是:
更新代码
'Load Pretrained Model'
loaded_model = keras.models.load_model('pretrained_model')
#Freeze all model layer weights
loaded_model.trainable = False
input1 = np.expand_dims(x_train['input1'],1)
input2 = np.expand_dims(x_train['input2'], 1)
input3 = x_train['input3']
#Redefine Input Layers for ANN
input1 = Input(shape = (input1.shape[1],), name = "input1")
input2 = Input(shape = (input2.shape[1],), name = "input2")
input3 = Input(shape = (input3.shape[1],), name = "input2")
base_inputs = [input1, input2, input3]
x = loaded_model(base_inputs, training = False)
x = Dense(64, activation = "relu", kernel_regularizer=regularizers.l2(0.01))(x)
output = Dense(1, activation = "sigmoid")(x)
top_model = Model(inputs = base_inputs, outputs = output)
# Compile the Model
top_model.compile(loss='mse', optimizer = Adam(lr = 0.0001), metrics = ['mse'])
这无法正常工作,我不确定如何启动和运行它。我正在努力解决这个问题并且经常遇到这个错误:
AttributeError: 'Dense' object has no attribute 'shape'
有什么想法吗?
【问题讨论】:
标签: python tensorflow keras neural-network