如何塑造从完全连接到 4-D 的张量

how to shape tensor from fully connected to to 4-D

我是 tensorflow 的新手。我试图在自动编码器中添加 CNN。我使用的是来自 tflearn 的示例代码。我的初始代码是

X, Y, testX, testY = mnist.load_data(one_hot=True)
# Building the encoder
encoder = tflearn.input_data(shape=[None, 28* 28*1], name='input')
encoder = tflearn.fully_connected(encoder, 256)

# Building the decoder
decoder = tflearn.fully_connected(encoder, 256)
decoder = tflearn.fully_connected(decoder, 784, activation='sigmoid')

# Regression, with mean square error
net = tflearn.regression(decoder, optimizer='adam', learning_rate=0.001,
                         loss='mean_square', metric=None)
# Training the auto encoder
model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(X, X, n_epoch=20, validation_set=(testX, testX),
          run_id="auto_encoder", batch_size=256)

现在我在像这样构建解码器之前添加了 CNN 代码。

encoder = tflearn.input_data(shape=[None, 28* 28*1], name='input')
encoder = tflearn.fully_connected(encoder, 256)

# my modification
network = conv_3d(encoder, 32, 3, activation='relu', regularizer="L2")

# Building the decoder
decoder = tflearn.fully_connected(network, 256)
decoder = tflearn.fully_connected(decoder, 784, activation='sigmoid')

但是我得到以下错误

    network = conv_2d(encoder, 32, 3, activation='relu', regularizer="L2")
  File "/usr/local/lib/python3.5/dist-packages/tflearn/layers/conv.py", line 66, in conv_2d
    assert len(input_shape) == 4, "Incoming Tensor shape must be 4-D"
AssertionError: Incoming Tensor shape must be 4-D

现在如何将此编码器变量转换为 4D 张量?或者还有其他方法可以解决问题吗?

所以这个答案只是一个简单的拼写错误更正。

encoder = tflearn.input_data(shape=[None, 28* 28*1], name='input')
encoder = tflearn.fully_connected(encoder, 256)

# Correction here 3d to 2d 
network = conv_2d(encoder, 32, 3, activation='relu', regularizer="L2")

# Building the decoder
decoder = tflearn.fully_connected(network, 256)
decoder = tflearn.fully_connected(decoder, 784, activation='sigmoid')