Dense层
全连接层
TimeDistributed层
接收数据至少三维,对于底层数据进行全连接,类似Dense。
e.x.对于32 video 样本,每个样本有10个时刻 128x128 RGB 的图像数据,最底层数据维度为3. The batch input shape is (32, 10, 128, 128, 3)。
经过TimeDistributed层后维度为[32,10,128,1],对于最底层数据进行降维。
Embedding层
嵌入层,主要用于语言分析中降维
model = tf.keras.Sequential()
model.add(tf.keras.layers.Embedding(1000, 64, input_length=10))
# The model will take as input an integer matrix of size (batch,
# input_length), and the largest integer (i.e. word index) in the input
# should be no larger than 999 (vocabulary size).
# Now model.output_shape is (None, 10, 64), where `None` is the batch
# dimension.
input_array = np.random.randint(1000, size=(32, 10))
model.compile('rmsprop', 'mse')
output_array = model.predict(input_array)
print(output_array.shape)
InputLayer输出层
神经网络的输出接口
在Sequential model中如果在InputLayer后的层中使用input_shape将会跳过输入层。输入层只提供接口不进行运算。
model = tf.keras.Sequential([
tf.keras.layers.InputLayer(input_shape=(4))])
model.predict([1,3,3,4])
#out>:array([1., 3., 3., 4.], dtype=float32)