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)
Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐