Tensorflowで3Dデータを処理するLSTM RNNを構築しようとしています。 this紙から、グリッドLSTM RNNはn次元にすることができます。私のネットワークのアイデアは、3Dボリューム[depth, x, y]
であり、ネットワークは[depth, x, y, n_hidden]
である必要があります。ここで、n_hidden
はLSTMセル再帰呼び出しの数です。アイデアは、各ピクセルがLSTM再帰呼び出しの独自の "文字列"を取得することです。Tensorflow Grid LSTM RNN TypeError
出力は[depth, x, y, n_classes]
である必要があります。私は、バイナリセグメンテーションやってる - 前景と背景のだと思うが、そのクラスの数がちょうど2
# Network Parameters
n_depth = 5
n_input_x = 200 # MNIST data input (img shape: 28*28)
n_input_y = 200
n_hidden = 128 # hidden layer num of features
n_classes = 2
# tf Graph input
x = tf.placeholder("float", [None, n_depth, n_input_x, n_input_y])
y = tf.placeholder("float", [None, n_depth, n_input_x, n_input_y, n_classes])
# Define weights
weights = {}
biases = {}
# Initialize weights
for i in xrange(n_depth * n_input_x * n_input_y):
weights[i] = tf.Variable(tf.random_normal([n_hidden, n_classes]))
biases[i] = tf.Variable(tf.random_normal([n_classes]))
def RNN(x, weights, biases):
# Prepare data shape to match `rnn` function requirements
# Current data input shape: (batch_size, n_input_y, n_input_x)
# Permuting batch_size and n_input_y
x = tf.reshape(x, [-1, n_input_y, n_depth * n_input_x])
x = tf.transpose(x, [1, 0, 2])
# Reshaping to (n_input_y*batch_size, n_input_x)
x = tf.reshape(x, [-1, n_input_x * n_depth])
# Split to get a list of 'n_input_y' tensors of shape (batch_size, n_hidden)
# This input shape is required by `rnn` function
x = tf.split(0, n_depth * n_input_x * n_input_y, x)
# Define a lstm cell with tensorflow
lstm_cell = grid_rnn_cell.GridRNNCell(n_hidden, input_dims=[n_depth, n_input_x, n_input_y])
# lstm_cell = rnn_cell.MultiRNNCell([lstm_cell] * 12, state_is_tuple=True)
# lstm_cell = rnn_cell.DropoutWrapper(lstm_cell, output_keep_prob=0.8)
outputs, states = rnn.rnn(lstm_cell, x, dtype=tf.float32)
# Linear activation, using rnn inner loop last output
# pdb.set_trace()
output = []
for i in xrange(n_depth * n_input_x * n_input_y):
#I'll need to do some sort of reshape here on outputs[i]
output.append(tf.matmul(outputs[i], weights[i]) + biases[i])
return output
pred = RNN(x, weights, biases)
pred = tf.transpose(tf.pack(pred),[1,0,2])
pred = tf.reshape(pred, [-1, n_depth, n_input_x, n_input_y, n_classes])
# pdb.set_trace()
temp_pred = tf.reshape(pred, [-1, n_classes])
n_input_y = tf.reshape(y, [-1, n_classes])
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(temp_pred, n_input_y))
ある現在、私はエラーを取得しています:TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
それはRNNの使う初期の後に発生します。当然のoutputs, states = rnn.rnn(lstm_cell, x, dtype=tf.float32)
x
は、私がここで何種類GridRNNCell
戻り、任意のhelpeを伝えることができません
タイプのfloat32のでしょうか?これは問題になる可能性があります。私はこれにもっと議論を定義するべきですか? input_dims
は意味がありますが、output_dims
はどうすればよいですか?
これはcontrib
コードのバグですか?
GridRNNCellはcontribの中に位置しています/ grid_rnn /パイソン/ OPS/grid_rnn_cell.py
私はこのインターフェイスもやっています。私はあなたの質問への答えを知らないが、input_dimsは次元ではなくサイズであるべきですか? – jstaker7
@ jstaker7正しいですが、input_dimsが正しくありません。私は何が正しいのか分からないと言わなければならないが。あなたはこのパラムを理解していますか? –
まだ分かりません。私は元のプルリクエストの明確化を求めました:https://github.com/tensorflow/tensorflow/pull/1665 – jstaker7