[英]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.