tensorflow具备许多优秀的函数和功能,比如tensorboard,keras作为tensorflow的高级API, 封装很多tensorflow的代码,使得代码模块化,非常方便。
当然,由于keras的模型和层与tensorflow的张量高度兼容,可以用keras建模,用tensorflow输入输出。
例如下面的例子:
import tensorflow as tf
from keras import backend as K
from keras.layers import Dense
from keras.objectives import categorical_crossentropy
from keras.metrics import categorical_accuracy as accuracy
from tensorflow.examples.tutorials.mnist import input_data
# create a tf session,and register with keras。
sess = tf.Session()
K.set_session(sess)
# this place holder is the same with input layer in keras
img = tf.placeholder(tf.float32, shape=(None, 784))
# keras layers can be called on tensorflow tensors
x = Dense(128, activation='relu')(img)
x = Dense(128, activation='relu')(x)
preds = Dense(10, activation=