[英]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 Tensor? 还是有其他方法可以解决问题?
因此,答案是一个简单的错字更正。
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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.