2017-12-01 12 views
3

자, 그럼 나와 함께 곰. 그래서 내 코드입니다 :TypeError : 예상 된 바이너리 또는 유니 코드 문자열, 목록이 있습니다. Tensorflow

import tensorflow as tf 
import os 
import pickle 
from numpy import asarray, reshape 

os.chdir('PATH') 

with open('xSensor.pkl','rb') as file: 
    x_train = asarray(pickle.load(file)) 

with open('ySensor.pkl','rb') as file: 
    y_train = asarray(pickle.load(file)) 

def neural_network(data): 
    n_nodes_h1 = 1000 
    n_nodes_h2 = 1000 
    n_nodes_h3 = 500 

    hidden_layer_1 = { 
     'weights': tf.Variable(tf.random_normal([13, n_nodes_h1],dtype=tf.float64)), 
     'biases': tf.Variable(tf.random_normal([n_nodes_h1],dtype=tf.float64)) 
    } 

    #Omitting some code that just defines a couple more layers in the same format as above 

    layer_1 = tf.matmul(data, hidden_layer_1['weights']) + hidden_layer_1['biases'] 
    layer_1 = tf.nn.relu(layer_1) 

    #Omitting more code. 

    output = tf.matmul(layer_3, output['weights']) + output['biases'] 

    return output 


def train_network(x_t,y_t): 
    x = tf.placeholder(tf.float64, shape=[None, 13]) 
    y = tf.placeholder(tf.float64) 
    prediction = neural_network(x_t) 
    y_t = reshape(y_t,(700,1)) 
    cost = tf.reduce_mean(tf.losses.mean_squared_error(labels=y_t, predictions=prediction)) 
    optimizer = tf.train.AdamOptimizer(0.005).minimize(cost) #learning rate by default is 0.01 
    n_epochs = 1000 

    with tf.Session() as sess: 
     sess.run(tf.global_variables_initializer()) 
     for _ in range(0, n_epochs): 
      x_ = sess.run([optimizer,cost], feed_dict={x: x_t, y: y_t}) 
      print("Loss is: ", x_[1]) 



train_network(x_train,y_train) 

그리고 여기에 오류 로그입니다 : 너무 많은 코드를 게시

Traceback (most recent call last): 
    File "C:/Users/my system/Desktop/height_sensor.py", line 94, in <module> 
    train_network(x_train,y_train) 
    File "C:/Users/my system/Desktop/height_sensor.py", line 77, in train_network 
    prediction = neural_network(x_t) 
    File "C:/Users/my system/Desktop/height_sensor.py", line 59, in neural_network 
    layer_1 = tf.matmul(data, hidden_layer_1['weights']) + hidden_layer_1['biases'] 
    File "C:\Users\my system\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\math_ops.py", line 1844, in matmul 
    a = ops.convert_to_tensor(a, name="a") 
    ...etc... 
TypeError: Expected binary or unicode string, got [15.0126, 1.38684, 27.6, 1.6323, -0.624113, 8.97763, 2.06581, 8.88303, -0.689839, 9.13284, 353.183, 349.178, 210.498] 

Process finished with exit code 1 

미안 해요, waaaay를 덜 게시하고 싶어하지만 난 한 가지 것을 생략 할 수 있음을 걱정했다 그 오류가 발생했습니다. 누구든지 올바른 방향으로 나를 가리키면 너무 행복 할거야. 감사합니다.

답변

1

모든 코드를 게시하는 것이 좋습니다. 특히 모든 오류 추적을 게시하는 것이 좋습니다. 가짜 데이터로 코드를 실행할 수 있습니다. 가장 좋은 방법은 피클이 x_train의 값을 반환하는 방식과 관련이 있다는 것입니다. 배열에 너무 많은 중첩이있을 수 있습니다. 나는 전체 추적에 더 많은 것을 도울 수 있을지도 모르지만, 어떤면에서는 x_train의 일부를 출력하고 그것이 올바른 형식인지 확인하는 것이 좋습니다.