2016-05-15 5 views
2

ConvNetを作成します。同じサイズの出力を入力の1つとして使用します。そこで、TFLearnライブラリを使って実装しました。私はこれらの目的を満たす簡単な例を望んでいたので、入力と同じ出力サイズに対してゼロパディング付きの畳み込みレイヤーを1つだけ設定しました。以下はコードです:TensorFlow/TFLearn:ValueError:Tensor u'TargetsData/Y:0のシェイプ(256,400,400)の形状を '(?、64)'に変換できません。

X = X.reshape([-1, 400, 400, 1]) 
Y = Y.reshape([-1, 400, 400, 1]) 
testX = testX.reshape([-1, 400, 400, 1]) 
testY = testY.reshape([-1, 400, 400, 1]) 
X, mean = du.featurewise_zero_center(X) 
testX = du.featurewise_zero_center(testX, mean) 


# Building a Network 
net = tflearn.input_data(shape=[None, 400, 400, 1]) 
net = tflearn.conv_2d(net, 64, 3, padding='same', activation='relu', bias=False) 
sgd = tflearn.SGD(learning_rate=0.1, lr_decay=0.96, decay_step=300) 
net = tflearn.regression(net, optimizer='sgd', 
        loss='categorical_crossentropy', 
        learning_rate=0.1) 
# Training 
model = tflearn.DNN(net, checkpoint_path='model_network', 
       max_checkpoints=10, tensorboard_verbose=3) 
model.fit(X, Y, n_epoch=100, validation_set=(testX, testY), 
     show_metric=True, batch_size=256, run_id='network_test') 

しかし、これらのコードは、私が検索し、いくつかの書類をチェックしました

ValueError: Cannot feed value of shape (256, 400, 400) for Tensor u'TargetsData/Y:0', which has shape '(?, 64)' 

誤差を生じるが、私はこの仕事を得るように見えることはできません。

+0

私はTFのAPIに精通していないんだけど、:

オートエンコーダの

は、次のようにあなたは自分自身のデータでそれを適応し、INPUT_DATA形状を変更することができ、MNISTのための畳み込みオートエンコーダであります'testX = du.featurewise_zero_center(testX、mean)'の後に 'testX'がタプルではないでしょうか? – erip

+0

@erip申し訳ありませんが、私はヘッダーの部分を省略しました。この行は、 'tflearn.data_utils as duから'得られたものです。ここで、 'tflearn.data_utils'は、データ前処理に関するヘッダファイルです。 – David

+0

確かに、Xを返し、上記の意味です。以下はtestXだけを返します。 – erip

答えて

1

あなたのconvnet出力は(None、64)の形をしていますが、(None、400,400)の形のターゲットデータ(ラベル)を与えているという問題があります。あなたのコードで何をしたいのか分かりません。いくつかの自動エンコーディングをしようとしていますか?それとも分類作業の対象ですか?

from __future__ import division, print_function, absolute_import 

import numpy as np 
import matplotlib.pyplot as plt 
import tflearn 
import tflearn.data_utils as du 

# Data loading and preprocessing 
import tflearn.datasets.mnist as mnist 
X, Y, testX, testY = mnist.load_data(one_hot=True) 

X = X.reshape([-1, 28, 28, 1]) 
testX = testX.reshape([-1, 28, 28, 1]) 
X, mean = du.featurewise_zero_center(X) 
testX = du.featurewise_zero_center(testX, mean) 

# Building the encoder 
encoder = tflearn.input_data(shape=[None, 28, 28, 1]) 
encoder = tflearn.conv_2d(encoder, 16, 3, activation='relu') 
encoder = tflearn.max_pool_2d(encoder, 2) 
encoder = tflearn.conv_2d(encoder, 8, 3, activation='relu') 
decoder = tflearn.upsample_2d(encoder, 2) 
decoder = tflearn.conv_2d(encoder, 1, 3, activation='relu') 

# 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=10, validation_set=(testX, testX), 
      run_id="auto_encoder", batch_size=256) 

# Encoding X[0] for test 
print("\nTest encoding of X[0]:") 
# New model, re-using the same session, for weights sharing 
encoding_model = tflearn.DNN(encoder, session=model.session) 
print(encoding_model.predict([X[0]])) 

# Testing the image reconstruction on new data (test set) 
print("\nVisualizing results after being encoded and decoded:") 
testX = tflearn.data_utils.shuffle(testX)[0] 
# Applying encode and decode over test set 
encode_decode = model.predict(testX) 
# Compare original images with their reconstructions 
f, a = plt.subplots(2, 10, figsize=(10, 2)) 
for i in range(10): 
    a[0][i].imshow(np.reshape(testX[i], (28, 28))) 
    a[1][i].imshow(np.reshape(encode_decode[i], (28, 28))) 
f.show() 
plt.draw() 
plt.waitforbuttonpress() 
+0

ありがとうございました。また、 'net = tflearn.conv_2d(net、64、3、padding = 'same'、activation = 'relu')の入力と同じサイズの出力に対して' padding = 'same'バイアス=偽) ' – David

関連する問題