Keras

Post date: Jan 8, 2019 2:27:32 PM

一段代码

from keras.layers import Input, Dense from keras.models import Model # This returns a tensor inputs = Input(shape=(784,)) # a layer instance is callable on a tensor, and returns a tensor x = Dense(64, activation='relu')(inputs) x = Dense(64, activation='relu')(x) predictions = Dense(10, activation='softmax')(x) # This creates a model that includes # the Input layer and three Dense layers model = Model(inputs=inputs, outputs=predictions) model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy']) model.fit(data, labels) # starts training

使用Keras Model时,outputs需要是keras tensor, 如果中间有tensorflow操作时,可以考虑使用Lambda封装成Keras Layers. 博文里说的更清楚。