2016-12-27 7 views
0

Tensorflow feed_dictにリストを供給できません。コード:Tensorflow feed_dict浮動小数点のリストとInvalidArgumentError

InvalidArgumentError(トレースバックするための上記参照):

import tensorflow as tf 
import numpy as np 
from sklearn.model_selection import train_test_split 
from math import ceil 
BATCH_SIZE = 100 

# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3 
x_data = np.random.rand(13000).astype(np.float32) 
y_data = x_data * 0.1 + 0.3 

x_train, x_test, y_train, y_test = train_test_split(x_data, y_data, test_size=0.3) 


# Try to find values for W and b that compute y_data = W * x_data + b 
# (We know that W should be 0.1 and b 0.3, but TensorFlow will 
# figure that out for us.) 


x_in = tf.placeholder(tf.float32, shape=[BATCH_SIZE], name='x_in') 
y_in = tf.placeholder(tf.float32, shape=[BATCH_SIZE], name='y_in') 

W = tf.Variable(tf.random_uniform([1], -1.0, 1.0)) 
b = tf.Variable(tf.zeros([1])) 
y = W * x_in + b 

# Minimize the mean squared errors. 
loss = tf.reduce_mean(tf.square(y - y_in)) 
optimizer = tf.train.GradientDescentOptimizer(0.5) 
train = optimizer.minimize(loss) 

# Before starting, initialize the variables. We will 'run' this first. 
init = tf.global_variables_initializer() 

# Launch the graph. 
sess = tf.Session() 
sess.run(init) 


batchesCount = ceil(len(x_train)/BATCH_SIZE) 

# Fit the line. 
for curBatchId in range(batchesCount): 
    batchStart = curBatchId * BATCH_SIZE 
    xf = x_train[batchStart: BATCH_SIZE] 
    yf = y_train[batchStart: BATCH_SIZE] 

    sess.run(train, feed_dict={x_in: xf, y_in:yf}) 

は私を与えるあなたはDTYPEフロートとプレースホルダテンソル 'x_in' の値 を供給し、[100]
を形成しなければなりません[ノード:x_in = Placeholderdtype = DT_FLOAT、形状= [100]、 _device = "/仕事:localhostの/レプリカ:0 /タスク:0/CPU:0"]]のコードで間違った

は何ですか、私の外見のためにそれはDTYPEフロートと

プレースホルダテンソル 'x_in' を通過するような形状と[100]

答えて

2

あなたは形状[100]のテンソルを渡す必要がありますので、私はあなたがやってみたかったと思います:

for curBatchId in range(batchesCount): 
    batchStart = curBatchId * BATCH_SIZE 
    xf = x_train[batchStart: batchStart + BATCH_SIZE] 
    yf = y_train[batchStart: batchStart + BATCH_SIZE] 
関連する問題