tf.keras.layers.Dense() 示例

import tensorflow as tf
dense = tf.keras.layers.Dense(
    7,  # 输出最后1维的维度
    activation="relu"  # 激活函数
)
print(dense)
<tensorflow.python.keras.layers.core.Dense object at 0x0000026B5A025820>

input的维度必须是大于1维

inputs = tf.random.normal([
    32,  # 第1个维度是样本数
    10,
    8,
])
print(inputs.shape)
(32, 10, 8)

output的维度会继承上层的维度

output = dense(inputs)
print(output.shape)
(32, 10, 7)

猜你喜欢

转载自blog.csdn.net/weixin_44493841/article/details/121419182