你可以很容易地在TF中使用Keras的函数API(用TF 2.0测试过):
import tensorflow as tf
# Image
input_1 = tf.keras.layers.Input(shape=(28, 28, 1))
conv2d_1 = tf.keras.layers.Conv2D(64, kernel_size=3,
activation=tf.keras.activations.relu)(input_1)
# Second conv layer :
conv2d_2 = tf.keras.layers.Conv2D(32, kernel_size=3,
activation=tf.keras.activations.relu)(conv2d_1)
# Flatten layer :
flatten = tf.keras.layers.Flatten()(conv2d_2)
# The other input
input_2 = tf.keras.layers.Input(shape=(1,))
dense_2 = tf.keras.layers.Dense(5, activation=tf.keras.activations.relu)(input_2)
# Concatenate
concat = tf.keras.layers.Concatenate()([flatten, dense_2])
n_classes = 4
# output layer
output = tf.keras.layers.Dense(units=n_classes,
activation=tf.keras.activations.softmax)(concat)
full_model = tf.keras.Model(inputs=[input_1, input_2], outputs=[output])
print(full_model.summary())
这给了你
the model you are looking for.