Tensorflow常用层学习笔记

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_dimInteger. Size of the vocabulary, i.e. maximum integer index + 1.单词数量,影响内部运算参数,随便设置
output_dimInteger. Dimension of the dense embedding.嵌入维度——影响输出
input_lengthLength 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_shapeShape tuple (not including the batch axis), or TensorShape instance (not including the batch axis).
batch_sizeOptional input batch size (integer or None).
dtypeOptional 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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值