0

지금까지 내가 쓴 다음 코드 :tensorflow로 작성된 GRU 기반 RNN을 어떻게 완료 할 수 있습니까?

import pickle 
import numpy as np 
import pandas as pd 
import tensorflow as tf 

# load pickled objects (x and y) 
x_input, y_actual = pickle.load(open('sample_input.pickle', 'rb')) 
x_input = np.reshape(x_input, (50, 1)) 
y_actual = np.reshape(y_actual, (50, 1)) 

# parameters 
batch_size = 50 
hidden_size = 100 

# create network graph 
input_data = tf.placeholder(tf.float32, [batch_size, 1]) 
output_data = tf.placeholder(tf.float32, [batch_size, 1]) 

cell = tf.nn.rnn_cell.GRUCell(hidden_size) 

initial_state = cell.zero_state(batch_size, tf.float32) 

hidden_state = initial_state 

output_of_cell, hidden_state = cell(inputs=input_data, state=hidden_state) 

init_op = tf.initialize_all_variables() 

softmax_w = tf.get_variable("softmax_w", [hidden_size, 1],) 
softmax_b = tf.get_variable("softmax_b", [1]) 

logits = tf.matmul(output_of_cell, softmax_w) + softmax_b 

probabilities = tf.nn.softmax(logits) 

sess = tf.Session() 
sess.run(init_op) 

something = sess.run([probabilities, hidden_state], feed_dict={input_data:x_input, output_data:y_actual}) 

#cost = tf.nn.sigmoid_cross_entropy_with_logits(logits, output_data) 


#sess.close() 

하지만의 oftmax_w/b로 초기화되지 않은 변수에 대한 오류를 얻고있다.

나는 Wb을 어떻게 사용해야하며 열차 운행을 수행하지 않습니다. 다음과 같은

뭔가 :

## some cost function 
## training operation minimizing cost function using gradient descent optimizer 

답변

3

tf.initialize_all_variables() 가져 "현재"그래프에서 변수를 설정합니다. tf.initialize_all_variables()을 호출 한 후에 softmax_wsoftmax_b을 작성 했으므로 tf.initialize_all_variables()의 목록에 없으므로 sess.run(init_op)을 실행할 때 초기화되지 않습니다. 다음 작동해야합니다 :

softmax_w = tf.get_variable("softmax_w", [hidden_size, 1],) 
softmax_b = tf.get_variable("softmax_b", [1]) 

init_op = tf.initialize_all_variables() 
+0

와우. 결국'sess.run (init_op)'을 호출하면 init_op = tf.initialize_all_variables()를 어디에 두든 상관없이 도움이 될 것입니다. – Sangram

관련 문제