Tensorflow常用层学习笔记

发布于:2022-11-01 ⋅ 阅读:(422) ⋅ 点赞:(0)

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层

        嵌入层,主要用于语言分析中降维

input_dim Integer. Size of the vocabulary, i.e. maximum integer index + 1.单词数量,影响内部运算参数,随便设置
output_dim Integer. Dimension of the dense embedding.嵌入维度——影响输出
input_length Length of input sequences, when it is constant. This argument is required if you are going to connectFlatten then Dense layers upstream (without it, the shape of the dense outputs cannot be computed).输入序列的长度,必须与输入数据的维度契合
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将会跳过输入层。输入层只提供接口不进行运算。

input_shape Shape tuple (not including the batch axis), or TensorShape instance (not including the batch axis).
batch_size Optional input batch size (integer or None).
dtype Optional datatype of the input. When not provided, the Keras default float type will be used.
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)

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到