You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TensorFlow构建自编码器:如何设置input_shape以生成模型摘要

解决Autoencoder模型build时input_shape无效的问题
  • 你的问题出在input_shape缺少了图像的通道维度。针对28x28的灰度图像(比如常见的MNIST数据集),TensorFlow需要明确指定通道数(单通道为1)。
  • 正确的input_shape设置应为(28, 28, 1),注意无需包含批量维度(None),因为build方法的input_shape仅需指定单个样本的形状。
  • 调整后的代码示例:
    autoencoder.build(input_shape=(28, 28, 1))
    autoencoder.summary()
    
  • 此外,也可以通过传入符合形状的测试张量自动构建模型,示例如下:
    import tensorflow as tf
    test_input = tf.random.normal([1, 28, 28, 1])
    test_output = autoencoder(test_input)
    autoencoder.summary()
    

内容的提问来源于stack exchange,提问作者deckard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 17:12:03