Tensorflow에서 3D 데이터를 처리하는 LSTM RNN을 작성하려고합니다. this 용지에서 Grid 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]
이어야합니다. 그것은 RNN를 사용하는 초기화 이후에 발생 TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
: 전경과 배경을 생각하는, 그래서 클래스의 수는 현재 내가 오류를 받고 있어요 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))
이다 - 나는 이진 분할을하고 있어요 물론 outputs, states = rnn.rnn(lstm_cell, x, dtype=tf.float32)
x
내가 여기 유형 GridRNNCell
반환, 어떤 helpe 말씀 드릴 수 없습니다
유형 float32이다? 이것은 문제 일 수 있습니다. 이것에 대한 더 많은 논쟁을 정의해야합니까? input_dims
은 의미가 있지만 무엇을 output_dims
으로해야합니까?
contrib
코드의 버그입니까?
GridRNNCell가있는 contrib에 위치/grid_rnn/파이썬/작전/grid_rnn_cell.py
저는이 인터페이스를 살펴 보겠습니다. 귀하의 질문에 대한 답을 모르겠지만 input_dims를 크기가 아닌 차원으로 나타내야합니까? – jstaker7
@ jstaker7 올바른지, input_dims가 올바르지 않습니다. 나는 옳은 것이 무엇인지 모른다. 이 param을 이해합니까? –
아직 확실하지 않습니다. 원래 pull 요청에 대한 설명을 요청했습니다. https://github.com/tensorflow/tensorflow/pull/1665 – jstaker7